首页 > 编程语言 > 详细

python regex note

时间:2016-05-08 19:37:59      阅读:278      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!