Python One

来源:互联网 发布:电脑编程c语言书籍 编辑:程序博客网 时间:2024/06/05 08:13

match and search:


match starts at pos 0 to find if there is any occurence of the pattern

search starts at any point


replace matched string with new string:


regex = re.compile(r'\w+(?=foo)')

newstr,number =  re.subn(regex,'bar','dddfoo eeefoo')

#newsrtr dddbar,eeebar

#number = 2


// With

With is like try(...) {} catch {} in Java, the managed resource will close automatically.


0 0
原创粉丝点击