zoukankan      html  css  js  c++  java
  • 正则表达式的常用方法

    一:贪婪和非贪婪

    贪婪:.* 尽可能多的去匹配

    非贪婪 .*? 尽可能少的去匹配

    content_str = """
    GET /?a=1&b=2 HTTP/1.1
    Host: 127.0.0.1:10012
    Connection: keep-alive
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
    Sec-Fetch-Mode: navigate
    Sec-Fetch-User: ?1
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
    Sec-Fetch-Site: none
    Accept-Encoding: gzip, deflate, br
    Accept-Language: zh-CN,zh;q=0.9
    """

    同样用search方法为例

    request_args = re.search(r"?(.*)s",content_str)
    print(request_args.group(1))
    # 结果
    a=1&b=2 HTTP/1.1
    
    
    request_args = re.search(r"?(.*?)s",content_str)
    print(request_args.group(1))
    # 结果
    a=1&b=2

    二:search方法

    python的re模块支持正则表达式,

    # TODO

     

  • 相关阅读:
    mvc UrlHelper
    Bootstrap框架
    Swiper插件
    JQuery 滚动条长度
    JQuery 全屏滚动
    JQuery TODOList
    JQuery 节点操作
    JQuery 事件委托 事件代理
    JQuery 关闭事件冒泡
    JQuery resize和scroll方法
  • 原文地址:https://www.cnblogs.com/meloncodezhang/p/12807229.html
Copyright © 2011-2022 走看看