March 2003
Intermediate to advanced
656 pages
39h 30m
English
search
r.search(s,start=0,end=sys.maxint)Returns an appropriate match object for the leftmost substring of
s, starting not before index
start and not reaching as far as index
end, that matches
r. When no such substring exists,
search returns None. For
example, to print all lines containing digits, one simple approach is
as follows:
import re
digs = re.compile(r'\d+')
for line in open('afile.txt'):
if digs.search(line): print line,