首页 > 代码库 > Regular Ex Notes
Regular Ex Notes
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 |
Regular Ex Notes
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。