March 2003
Intermediate to advanced
656 pages
39h 30m
English
match
r.match(s,start=0,end=sys.maxint)Returns an appropriate match object when a substring of
s, starting at index
start and not reaching as far as index
end, matches r.
Otherwise, match returns None.
Note that match is implicitly anchored at the
starting position start in
s. To search for a match with
r through s,
from start onwards, call
r
.search, not
r
.match. For example,
here’s how to print all lines in a file that start
with digits:
import re
digs = re.compile(r'\d+')
for line in open('afile.txt'):
if digs.match(line): print line,