码迷,mamicode.com
首页 > 编程语言 > 详细

python regex note

时间:2016-05-08 19:39:18      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:


  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.

 

 

 

 

 

 

 

 

 

 

 

 

 


6: re.DOTALL, re.I

python regex note

标签:

原文地址:http://www.cnblogs.com/xuezoushi/p/5471070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!