re模块中的compile函数

compile

compile(pattern,flag=0)

compile a regular expression pattern,return a pattern object

compile就像一个漏斗,指定漏斗规则,如三角形通过,圆形通过,字母通过,汉字通过等等,具体漏什么东西(str数值),可以使用的时候再决定

myCompile = re.compile('d')#指定漏斗规则 re.compile是个函数,但是返回值是个类,一个过滤方法的类,实例化后就可以用来过滤东西

myStr0 = 'today 12 is 34 so 56 beautiful 789'#str数值

myResult=myCompile.find_all(myStr0)#过滤str0

flags是个标记,就像吃东西会标注微辣、麻辣、不辣一样,flags是个证书值,但是不太好记,python帮大家记住。

原文地址:https://www.cnblogs.com/themost/p/6701634.html