Name
search
Synopsis
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,
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.