Update of /cvsroot/py-howto/pyhowto
In directory sc8-pr-cvs1:/tmp/cvs-serv7696
Modified Files:
regex.tex
Log Message:
Describe findall() and finditer(); bump version number
Index: regex.tex
===================================================================
RCS file: /cvsroot/py-howto/pyhowto/regex.tex,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** regex.tex 6 Apr 2003 23:35:20 -0000 1.16
--- regex.tex 7 Apr 2003 19:51:23 -0000 1.17
***************
*** 3,7 ****
% TODO:
% Document lookbehind assertions
- % Add section on findall, finditer methods
% Better way of displaying a RE, a string, and what it matches
% Mention optional argument to match.groups()
--- 3,6 ----
***************
*** 10,14 ****
\title{Regular Expression HOWTO}
! \release{0.04}
\author{A.M. Kuchling}
--- 9,13 ----
\title{Regular Expression HOWTO}
! \release{0.05}
\author{A.M. Kuchling}
***************
*** 465,468 ****
--- 464,494 ----
\end{verbatim}
+ Two \class{RegexObject} methods return all of the matches for a pattern.
+ \method{findall()} returns a list of matching strings:
+
+ \begin{verbatim}
+ >>> p = re.compile('\d+')
+ >>> p.findall('12 drummers drumming, 11 pipers piping, 10 lords a-leaping')
+ ['12', '11', '10']
+ \end{verbatim}
+
+ \method{findall()} has to create the entire list before it can be
+ returned as the result. In Python 2.2, the \method{finditer()} method
+ is also available, returning a sequence of \class{MatchObject} instances
+ as an iterator.
+
+ \begin{verbatim}
+ >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
+ >>> iterator
+ <callable-iterator object at 0x401833ac>
+ >>> for match in iterator:
+ ... print match.span()
+ ...
+ (0, 2)
+ (22, 24)
+ (29, 31)
+ \end{verbatim}
+
+
\subsection{Module-Level Functions}
***************
*** 1372,1376 ****
HTML or XML parser module for such tasks.)
! \subsection{Not using re.VERBOSE}
By now you've probably noticed that regular expressions are a very
--- 1398,1402 ----
HTML or XML parser module for such tasks.)
! \subsection{Not Using re.VERBOSE}
By now you've probably noticed that regular expressions are a very
|