- 18
- 0
- 约2.02万字
- 约 60页
- 2019-02-20 发布于江苏
- 举报
4.2.4 使用正则表达式对象 example = Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts.‘ pattern = pile(r\bb\w*\b,re.I) print pattern.sub(*,example) * is * than ugly. Explicit is * than implicit. Simple is * than complex. Complex is * than complicated. Flat is * than nested. Sparse is * than dense. Readability counts. 4.2.4 使用正则表达式对象 print pattern.sub(*,example,1) * is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. pattern = pile(r\bb\w*\b) print pattern.sub(*,example,1) Beautiful is * than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. 4.2.4 使用正则表达式对象 分割字符串: split(string[, maxsplit = 0]) -- list 4.2.4 使用正则表达式对象 example = rone,two,three.four/file\six?seven[eight]nine|ten‘ pattern = pile(r[,./\\?[\]\|]) pattern.split(example) [one, two, three, four, file, six, seven, eight, nine, ten] example = rone1two2three3four4file5six6seven7eight8nine9ten pattern = pile(r\d+) pattern.split(example) [one, two, three, four, file, six, seven, eight, nine, ten] example = rone two three four,file.six.seven,eight,nine9ten pattern = pile(r[\s,.\d]+) pattern.split(example) [one, two, three, four, file, six, seven, eight, nine, ten] 4.2.5 子模式与match对象 使用()表示一个子模式,即()内的内容作为一个整体出现,例如’(red)+’可以匹配’redred’、’redredred‘等多个重复’red’的情况。 telNumber = Suppose my Phone No. is 0535-1234567, yours is 010 his is 025 pattern = pile(r(\d{3,4})-(\d{7,8})) pattern.findall(telNumber) [(0535, 1234567), (010,, (025,] 4.2.5 子模式与match对象 正则表达式对象的match方法和search方法匹配成功后返回match对象。 match对象的主要方法有group()、groups()、groupdict()、start()、e
您可能关注的文档
- 大学生创业之案例分析.ppt
- 大学生心理健康教育第四章.ppt
- 丹佛斯变频器和PCS7通信.pptx
- 单踪示波器的工作原理.pptx
- 党课精品课件系列---太行山上的新愚公-李保国.ppt
- 倒计时红色元旦年会颁奖晚会PPT范本.pptx
- 倒装句强调句在写作中应用.ppt
- 低盐饮食从我做起0903.ppt
- 地理信息系统在民航空管飞行程序设计中的应用.ppt
- 第1节--细胞中的元素和化合物--第1课时.ppt
- 人教版九年级英语Unit 4曾害怕课件3a-4c.pdf
- 雅思口语考题回顾:朗阁海外考试研究中心2019年10月10日Part 1考题总结.pdf
- 2026届高三地理一轮复习课件小专题河流袭夺.pptx
- 【名师原创】复习专题5 三角函数 作者:合肥市第八中学 蒲荣飞名师工作室.docx
- 高中数学一轮复习 微专题2 抽象函数.docx
- 高中数学——复习专题4 空间向量与立体几何.docx
- 高中数学一轮复习 微专题3 空间几何体中的截面、轨迹问题.docx
- 高中数学一轮复习 微专题4 空间几何体的最值、范围问题.docx
- 导流洞施工质量通病防治手册.docx
- 江苏省徐州市第一中学、徐市第三中学等五校2026届高三上学期12月月考历史试题含答案.docx
最近下载
- 1消毒供应中心烫伤应急预案演练脚本.docx VIP
- 1消毒供应中心跌倒应急预案演练脚本.docx VIP
- 高中数学同步精品讲义:二次函数定(动)轴与定(动)区间六大题型汇总.pdf VIP
- 消毒供应中心跌倒应急预案脚本.doc VIP
- 学堂在线 雨课堂 学堂云 战场侦察监视技术与装备 章节测试答案.docx VIP
- 第五届新疆中小学生天文奥林匹克竞赛决赛试题答案-初中.docx.pdf VIP
- 学堂在线 雨课堂 学堂云 现代生活美学——花香茶之道 章节测试答案.docx VIP
- 软件工程专业培养方案.doc VIP
- 最新医疗废物管理条例.pptx
- 第五届新疆中小学生天文奥林匹克竞赛决赛试题答案-高中.docx.pdf VIP
原创力文档

文档评论(0)