zoukankan      html  css  js  c++  java
  • python regex note


      To remember python regex easily, we organise python regex notes from concrete to abstract, and from simple to sophisticated.

    I, Important character:

      1, Quantitive character:

        ? :[0,1],   *:[0,infi),  +:(0,infi),  {n}:[n rep],  {m,}:[m, infi),  {,n}:[0,n],  {m,n}:[m,n],  

        ? (nogreedy option)

       2, Begin and End:

         ^: beginning,   $: ending

      3, Making own character class:

        [abc]  ,[^abc]: ^ rep non
      4, Character classes:

         d,D,s,S,w,W
      5: dot (or wildcard) character:

        . ,   .*,  (.*) ? : rep nongreedy fashion

    II, Usefull regex arguments

      1, re.DOTALL : match all characters, including the newline character.

      2, re.I (re.IGNORECASE): ignore uppercase 

      3, re.VERBOSE : spread the regex over multiple lines with comments.

      4, | : we could use pipe character to cobine all three above arguments.

    III, generate regex procedure:

      1, regex = re.compile(r"")

      2.1.1, regex.search("")

      2.1.2, regex.search("").group(), (or regex.search("").group(No.)),  greedy defalut

      2.2, regex.findall("")

      2.3 regex.sub("")

      3 , re.compile(r'''( )''', re.VERBOSE) : to manage more complex regrexes.

  • 相关阅读:
    二叉树
    tomcat和jvm调优
    服务器正向代理
    LRU算法
    《转载》TCP三次握手中SYN,ACK,Seq三者的关系
    python的字符串、集合、for循环、异常等基础语法
    configparser_配置解析器
    hashlib模块
    悟_面向对象_小游戏和进阶
    面向对象_new,__eq__,__hash__
  • 原文地址:https://www.cnblogs.com/xuezoushi/p/5471070.html
Copyright © 2011-2022 走看看