![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
正则表达式
文章平均质量分 59
唐僧爱吃唐僧肉
这个作者很懒,什么都没留下…
展开
-
re.match函数讲解
之前一直对re.match函数的匹配方法感到困惑,今天用具体的例子来讲解一下re.match函数匹配到的不同内容: 第一组代码 import re line = "Cats are smarter than dogs" matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I) if matchObj: print("matchObj.group() : ", matchObj.group()) print("match原创 2021-06-10 19:20:08 · 5752 阅读 · 0 评论 -
常用的正则表达式讲解
1.对于带分数进行的转化 import re question = '3(1/2)' question = re.sub('(\d+)\((\d+/\d+)\)','(\\1+\\2)',question) print('question = ') print(question) 输出的对应结果为 question = (3+1/2) 这里的(\d+)对应前面的数值3,(对应3后面的左括号 序列 '\\' 匹配 "\",而 '\(' 则匹配 "(",'\)'匹配")" 接下来对应的(\d+ /原创 2021-05-08 18:52:52 · 389 阅读 · 0 评论