首页 > 其他 > 详细

Regular Ex Notes

时间:2015-01-14 00:33:34      阅读:369      评论:0      收藏:0      [点我收藏+]

https://docs.python.org/2/howto/regex.html

 

Identifiers:

\d  any number

\D  anything but a number

\s  space

\S  anything but a space

\w  any character

\W  anything but a character

.  any character, except for a newline

\b  the whitespace around words

\.  a period

 

Modifiers:

{1,3}  we‘re expecting 1-3

+  match 1 or more

?  match 0 or 1

*  match 0 or more

$  match the end of a string

^  matching the beginning of a string

|  either or 

[]  range or "variance" [A-Za-z1-5]

{x}  expecting "x" amount

 

White Space Characters:

\n  new line

\s  space

\t  tab

\e  escape

\f  form feed

\r  return

 

DONT FORGET!:

. + * ? { } $ ^ ( ) { } | \

need to escape them

 

Method/AttributePurpose
match() Determine if the RE matches at the beginning of the string.
search() Scan through a string, looking for any location where this RE matches.
findall() Find all substrings where the RE matches, and returns them as a list.
finditer() Find all substrings where the RE matches, and returns them as aniterator.

 

 

 

 

 

 

 

Method/AttributePurpose
group() Return the string matched by the RE
start() Return the starting position of the match
end() Return the ending position of the match
span() Return a tuple containing the (start, end) positions of the match

 

 

 

 

 

 

 

 

Regular Ex Notes

原文:http://www.cnblogs.com/keep-walking/p/4222814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!