码迷,mamicode.com
首页 > 其他好文 > 详细

Regular Ex Notes

时间:2015-01-14 00:34:01      阅读:268      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!