广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    如何运用PYTHON正则表达式的大括号

    来源:网络收集  点击:  时间:2024-08-31
    【导读】:
    运用PYTHON正则表达式的大括号{}工具/原料morePYTHON方法/步骤1/9分步阅读

    打开JUPYTER NOTEBOOK,新建一个PY文档。

    2/9

    我们要使用正则表达式,那么我们首先要引入re模块。

    3/9

    aRegex = re.compile(r(fire){4} now)

    search1 = aRegex.search(firefirefirefire now.)

    search1.group()

    {4}表示要有重复的4个,这样就可以避免多次输入造成的错误。

    4/9

    aRegex = re.compile(r(fire){4} now)

    search1 = aRegex.search(fire now.)

    search1.group()

    如果字符串里面没有4个,那么就会出错。

    5/9

    aRegex = re.compile(r(fire){} now)

    search1 = aRegex.search(fire now.)

    search1.group()

    如果大括号里面不填写数字,是会出现错误的。

    6/9

    aRegex = re.compile(r(fire){0} now)

    search1 = aRegex.search(fire now.)

    search1.group()

    如果大括号里面输入0,那么就是一个都不需要。

    7/9

    aRegex = re.compile(r(fire){1,4})

    search1 = aRegex.search(firefirefirefire now.)

    search1.group()

    我们可以定义一个范围,但是范围只会取最大值。

    8/9

    aRegex = re.compile(r(fire){1, 4})

    search1 = aRegex.search(firefirefirefire now.)

    search1.group()

    注意格式问题,逗号后面不要加空格。

    9/9

    aRegex = re.compile(r(fire){2,4}?)

    search1 = aRegex.search(firefirefirefire now.)

    search1.group()

    如果要取小数的话那么可以在后面加一个问号。

    注意事项

    留意格式的问题不然会出错

    PYTHON正则表达式大括号
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_1175412.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-05 15:13:36  耗时:0.024
    0.0243s