标签:
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/Attribute | Purpose |
---|---|
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/Attribute | Purpose |
---|---|
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 |
标签:
原文地址:http://www.cnblogs.com/keep-walking/p/4222814.html