@@ -12,11 +12,11 @@ Special characters::
12
12
R|S matches either regex R or regex S.
13
13
() Creates a capture group, and indicates precedence.
14
14
15
- No special chars do anything special inside `` [] `` , hence they don't need
15
+ Within `` [] ``, no special chars do anything special, hence they don't need
16
16
escaping, except for ``']' `` and ``'-' ``, which only need escaping if they are
17
- not the 1st char. e.g. ``'[]]' `` matches ``']' ``. ``'^' `` also has special meaning,
18
- it negates the group if it's the first character in the ``[] ``, and needs to be
19
- escaped if you want to match it literally.
17
+ not the 1st char. e.g. ``'[]]' `` matches ``']' ``. ``'^' `` also has special
18
+ meaning, it negates the group if it's the first character in the ``[] ``, and
19
+ needs to be escaped to match it literally.
20
20
21
21
Quantifiers::
22
22
@@ -27,7 +27,6 @@ Quantifiers::
27
27
{m,n} from m to n. 'm' defaults to 0, 'n' to infinity
28
28
{m,n}? from m to n, as few as possible
29
29
30
-
31
30
Special sequences::
32
31
33
32
\A Start of string
@@ -63,7 +62,7 @@ literals. Hence regex '``\n``' is same as regex '``\\n``'::
63
62
64
63
Extensions. These do not cause grouping, except for ``(?P<name>...) ``::
65
64
66
- (?iLmsux) Matches empty string, letters set re.X flags
65
+ (?iLmsux) Matches empty string, sets re.X flags
67
66
(?:...) Non-capturing version of regular parentheses
68
67
(?P<name>...) Creates a named capturing group.
69
68
(?P=<name>) Matches whatever matched previously named group
@@ -72,68 +71,64 @@ Extensions. These do not cause grouping, except for ``(?P<name>...)``::
72
71
(?!...) Negative lookahead assertion
73
72
(?<=...) Lookbehind assertion: Matches if preceded
74
73
(?<!...) Negative lookbehind assertion
75
- (?(id)yes|no) If group 'id' matched, match 'yes', else 'no'
76
-
74
+ (?(id)yes|no) Match 'yes' if group 'id' matched, else 'no'
77
75
78
- Flags for re.compile(). Combine with ``'|' ``::
76
+ Flags for re.compile(), etc . Combine with ``'|' ``::
79
77
80
- re.I re.IGNORECASE Ignore case
81
- re.L re.LOCALE Make \w, \b, and \s locale dependent
82
- re.M re.MULTILINE Multiline
83
- re.S re.DOTALL Dot matches all (including newline)
84
- re.U re.UNICODE Make \w, \b, \d, and \s unicode dependent
85
- re.X re.VERBOSE Verbose (unescaped whitespace in pattern
78
+ re.I == re.IGNORECASE Ignore case
79
+ re.L == re.LOCALE Make \w, \b, and \s locale dependent
80
+ re.M == re.MULTILINE Multiline
81
+ re.S == re.DOTALL Dot matches all (including newline)
82
+ re.U == re.UNICODE Make \w, \b, \d, and \s unicode dependent
83
+ re.X == re.VERBOSE Verbose (unescaped whitespace in pattern
86
84
is ignored, and '#' marks comment lines)
87
85
88
-
89
86
Module level functions::
90
87
91
- re.compile(pattern[, flags]) -> RegexObject
92
- re.match(pattern, string[, flags]) -> MatchObject
93
- re.search(pattner, string[, flags]) -> MatchObject
94
- re.findall(pattern, string[, flags]) -> list of strings
95
- re.finditer(pattern, string[, flags]) -> iter of MatchObjects
96
- re.split(pattern, string[, maxsplit, flags]) -> list of strings
97
- re.sub(pattern, repl, string[, count, flags]) -> string
98
- re.subn(pattern, repl, string[, count, flags]) -> (string, int)
99
- re.escape(string) -> string
100
- re.purge() # the re cache
101
-
88
+ compile(pattern[, flags]) -> RegexObject
89
+ match(pattern, string[, flags]) -> MatchObject
90
+ search(pattner, string[, flags]) -> MatchObject
91
+ findall(pattern, string[, flags]) -> list of strings
92
+ finditer(pattern, string[, flags]) -> iter of MatchObjects
93
+ split(pattern, string[, maxsplit, flags]) -> list of strings
94
+ sub(pattern, repl, string[, count, flags]) -> string
95
+ subn(pattern, repl, string[, count, flags]) -> (string, int)
96
+ escape(string) -> string
97
+ purge() # the re cache
102
98
103
99
RegexObjects (returned from ``compile() ``)::
104
100
105
- match(string[, pos, endpos]) -> MatchObject
106
- search(string[, pos, endpos]) -> MatchObject
107
- findall(string[, pos, endpos]) -> list of strings
108
- finditer(string[, pos, endpos]) -> iter of MatchObjects
109
- split(string[, maxsplit]) -> list of strings
110
- sub(repl, string[, count]) -> string
111
- subn(repl, string[, count]) -> (string, int)
112
- flags # int, passed to compile()
113
- groups # int, number of capturing groups
114
- groupindex # dict maps group names to ints
115
- pattern # string, passed to compile()
116
-
101
+ .match(string[, pos, endpos]) -> MatchObject
102
+ .search(string[, pos, endpos]) -> MatchObject
103
+ .findall(string[, pos, endpos]) -> list of strings
104
+ .finditer(string[, pos, endpos]) -> iter of MatchObjects
105
+ .split(string[, maxsplit]) -> list of strings
106
+ .sub(repl, string[, count]) -> string
107
+ .subn(repl, string[, count]) -> (string, int)
108
+ .flags # int passed to compile()
109
+ .groups # int number of capturing groups
110
+ .groupindex # {} maps group names to ints
111
+ .pattern # string passed to compile()
117
112
118
113
MatchObjects (returned from ``match() `` and ``search() ``)::
119
114
120
- expand(template) -> string # backslash and group expansion
121
- group([group1...]) -> string # or tuple of strings, one per arg
122
- groups([default]) -> tuple of all groups, non-matching=' default'
123
- groupdict([default]) -> dict of named groups, non-matching=' default'
124
- start([group]) -> int, start of substring matched by group
125
- end([group]) (group defaults to 0, the whole match)
126
- span([group]) -> tuple (match.start(group), match.end(group))
127
- pos -> the value passed to search() or match()
128
- endpos -> "
129
- lastindex -> int index of last matched capturing group
130
- lastgroup -> string name of last matched capturing group
131
- re -> the regex passed to search() or match()
132
- string -> the string passed to seatch () or match()
115
+ . expand(template) -> string, backslash and group expansion
116
+ . group([group1...]) -> string or tuple of strings, 1 per arg
117
+ . groups([default]) -> (,) of all groups, non-matching=default
118
+ . groupdict([default]) -> {} of named groups, non-matching=default
119
+ . start([group]) -> int, start/end of substring matched by group
120
+ . end([group]) (group defaults to 0, the whole match)
121
+ . span([group]) -> tuple (match.start(group), match.end(group))
122
+ . pos # value passed to search() or match()
123
+ . endpos # "
124
+ . lastindex # int index of last matched capturing group
125
+ . lastgroup # string name of last matched capturing group
126
+ . re # regex passed to search() or match()
127
+ . string # string passed to search () or match()
133
128
134
129
135
130
Gleaned from the python 2.7 're' docs. http://docs.python.org/library/re.html
136
131
137
- :Version: v0.3.0
132
+ :Version: v0.3.1
138
133
:Contact: tartley@tartley.com
139
134
0 commit comments