zoukankan      html  css  js  c++  java
  • 编译

    #当我们在Python中使用正则表达式时,re模块内部会做两件事情:
    1、编译正则表达式,如果正则表达式的字符串本身不合法,就会报错。
    2、用编译后的正则表达式匹配字符串。
    #如果一个正则表达式需要重复使用几千次,出于效率的考虑,我们可以预编译该正则表达式,这样重复使用时就不需要编译这个步骤,直接匹配即可,例如:
    1 #!/usr/bin/python3
    2 #-*-coding:UTF-8-*-
    3 #compile
    4 
    5 import re
    6 
    7 re_telephone=re.compile(r'^(d{3})-(d{3,8})$')
    8 print(re_telephone.match('010-12345').groups())
    9 print(re_telephone.match('010-8086').groups())
    #执行结果如下:
    1 D:Pythonworkspace>python compile.py
    2 ('010', '12345')
    3 ('010', '8086')
  • 相关阅读:
    HDU 5444 Elven Postman 二叉排序树
    HDU 5438 Ponds dfs模拟
    Gym
    markdown test
    Gym
    集训回顾
    UVALive
    UVALive
    UVALive
    codeforcres 589 J
  • 原文地址:https://www.cnblogs.com/DLHe/p/8339849.html
Copyright © 2011-2022 走看看