• python-re使用举例


    代码:

     1 import re
     2 
     3 text = "JGood is a handsome boy, he is cool, clever, and so on..."
     4 print(text)
     5 m = re.match(r"(w+)s", text)
     6 n = re.search(r"shan(ds)omes", text)
     7 if m:
     8     print("match: "(w+)s" ")
     9     print(m.group(0))
    10 else:
    11     print 'not match'  
    12 
    13 if n:
    14     print("search: "shan(ds)omes"")
    15     print(n.group(0))
    16 else:
    17     print 'not match'  

    执行结果:

    JGood is a handsome boy, he is cool, clever, and so on...
    match: "(w+)s"
    JGood
    search: "shan(ds)omes"
     handsome

    参考:

    http://www.cnblogs.com/sevenyuan/archive/2010/12/06/1898075.html

    正则表达式参考:

    http://www.runoob.com/regexp/regexp-syntax.html

    https://msdn.microsoft.com/zh-cn/library/ae5bf541(v=vs.80).aspx

  • 相关阅读:
    linux 时间同步
    sublime3 install python3
    Postfix的工作原理
    MySQL启动报错
    Socket server
    自定义静态网卡配置
    Nginx 404 500
    Pymysql
    Gitlab smtp 设置
    Windows 文件自动同步共享工具
  • 原文地址:https://www.cnblogs.com/moonpool/p/5695170.html
Copyright © 2020-2023  润新知