Python开发笔记之正则表达式的使用

  1. 查找正则表达式

    import re
    re_txt = re.compile(r'(d)*.txt')
    m = re_txt.search(src)
    if not m == None:
        m.group(0) #complete str
        m.group(1) # first group string
    
  2. 匹配正则表达式

    if re.match(r'(d)*.txt',path):
        print("match")
    else:
        print("not match")
    
  3. 分割正则表达式

    list = re.split(r'd',string)   
    
  4. 替换正则表达式

    re.sub(r'd*',rep,src)
    

参考

https://docs.python.org/2/library/re.html

原文地址:https://www.cnblogs.com/peaceWang/p/Python-kai-fa-bi-ji-zhi-zheng-ze-biao-da-shi-de-sh.html