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.

  • 相关阅读:
    oracl遇到的问题
    Ubuntu安装pyucharm的专业版本
    android adb logcat详解(三)
    android monkey压力测试(二)
    android adb常用命令(一)
    python *args 与 **kwargs
    python中带有下划线的变量和函数
    如何区分Python package
    Python Importlib.import_module动态导入模块
    python os.path.dirname(__file__)
  • 原文地址:https://www.cnblogs.com/xuezoushi/p/5471070.html
Copyright © 2011-2022 走看看