Skip to content

Commit 873cc12

Browse files
committedNov 15, 2011
minor tidyings, add pdf to .gitignore
1 parent 21937f8 commit 873cc12

File tree

2 files changed

+49
-53
lines changed

2 files changed

+49
-53
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
cheatsheet.pdf
12
activate
23
env

‎cheatsheet.rst

+48-53
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Special characters::
1212
R|S matches either regex R or regex S.
1313
() Creates a capture group, and indicates precedence.
1414

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
1616
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.
2020

2121
Quantifiers::
2222

@@ -27,7 +27,6 @@ Quantifiers::
2727
{m,n} from m to n. 'm' defaults to 0, 'n' to infinity
2828
{m,n}? from m to n, as few as possible
2929

30-
3130
Special sequences::
3231

3332
\A Start of string
@@ -63,7 +62,7 @@ literals. Hence regex '``\n``' is same as regex '``\\n``'::
6362

6463
Extensions. These do not cause grouping, except for ``(?P<name>...)``::
6564

66-
(?iLmsux) Matches empty string, letters set re.X flags
65+
(?iLmsux) Matches empty string, sets re.X flags
6766
(?:...) Non-capturing version of regular parentheses
6867
(?P<name>...) Creates a named capturing group.
6968
(?P=<name>) Matches whatever matched previously named group
@@ -72,68 +71,64 @@ Extensions. These do not cause grouping, except for ``(?P<name>...)``::
7271
(?!...) Negative lookahead assertion
7372
(?<=...) Lookbehind assertion: Matches if preceded
7473
(?<!...) 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'
7775

78-
Flags for re.compile(). Combine with ``'|'``::
76+
Flags for re.compile(), etc. Combine with ``'|'``::
7977

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
8684
is ignored, and '#' marks comment lines)
8785

88-
8986
Module level functions::
9087

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
10298

10399
RegexObjects (returned from ``compile()``)::
104100

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()
117112

118113
MatchObjects (returned from ``match()`` and ``search()``)::
119114

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()
133128

134129

135130
Gleaned from the python 2.7 're' docs. http://docs.python.org/library/re.html
136131

137-
:Version: v0.3.0
132+
:Version: v0.3.1
138133
:Contact: tartley@tartley.com
139134

0 commit comments

Comments
 (0)