mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Minor nits.
Moved IGNORECASE & friends to "top level" definitions following compile(),
since there is no other case of nesting in the manual.
Use {memberdesc} and {methoddesc} as appropriate.
			
			
This commit is contained in:
		
							parent
							
								
									dff21a6b93
								
							
						
					
					
						commit
						76547c5631
					
				
					 2 changed files with 118 additions and 114 deletions
				
			
		| 
						 | 
					@ -126,7 +126,8 @@ simplest expressions.
 | 
				
			||||||
be listed individually, or a range of characters can be indicated by
 | 
					be listed individually, or a range of characters can be indicated by
 | 
				
			||||||
giving two characters and separating them by a '-'.  Special
 | 
					giving two characters and separating them by a '-'.  Special
 | 
				
			||||||
characters are not active inside sets.  For example, \code{[akm\$]}
 | 
					characters are not active inside sets.  For example, \code{[akm\$]}
 | 
				
			||||||
will match any of the characters 'a', 'k', 'm', or '\$'; \code{[a-z]}
 | 
					will match any of the characters \character{a}, \character{k},
 | 
				
			||||||
 | 
					\character{m}, or \character{\$}; \code{[a-z]}
 | 
				
			||||||
will match any lowercase letter and \code{[a-zA-Z0-9]} matches any
 | 
					will match any lowercase letter and \code{[a-zA-Z0-9]} matches any
 | 
				
			||||||
letter or digit.  Character classes such as \code{\e w} or \code {\e
 | 
					letter or digit.  Character classes such as \code{\e w} or \code {\e
 | 
				
			||||||
S} (defined below) are also acceptable inside a range.  If you want to
 | 
					S} (defined below) are also acceptable inside a range.  If you want to
 | 
				
			||||||
| 
						 | 
					@ -278,6 +279,27 @@ The module defines the following functions and constants, and an exception:
 | 
				
			||||||
  \var{flags} value.  Values can be any of the following variables,
 | 
					  \var{flags} value.  Values can be any of the following variables,
 | 
				
			||||||
  combined using bitwise OR (the \code{|} operator).
 | 
					  combined using bitwise OR (the \code{|} operator).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The sequence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{verbatim}
 | 
				
			||||||
 | 
					prog = re.compile(pat)
 | 
				
			||||||
 | 
					result = prog.match(str)
 | 
				
			||||||
 | 
					\end{verbatim}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					is equivalent to
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{verbatim}
 | 
				
			||||||
 | 
					result = re.match(pat, str)
 | 
				
			||||||
 | 
					\end{verbatim}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					but the version using \function{compile()} is more efficient when the
 | 
				
			||||||
 | 
					expression will be used several times in a single program.
 | 
				
			||||||
 | 
					%(The compiled version of the last pattern passed to
 | 
				
			||||||
 | 
					%\function{regex.match()} or \function{regex.search()} is cached, so
 | 
				
			||||||
 | 
					%programs that use only a single regular expression at a time needn't
 | 
				
			||||||
 | 
					%worry about compiling regular expressions.)
 | 
				
			||||||
 | 
					\end{funcdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{I}
 | 
					\begin{datadesc}{I}
 | 
				
			||||||
\dataline{IGNORECASE}
 | 
					\dataline{IGNORECASE}
 | 
				
			||||||
Perform case-insensitive matching; expressions like \code{[A-Z]} will match
 | 
					Perform case-insensitive matching; expressions like \code{[A-Z]} will match
 | 
				
			||||||
| 
						 | 
					@ -319,27 +341,6 @@ leftmost such \code{\#} through the end of the line are ignored.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{datadesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The sequence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{verbatim}
 | 
					 | 
				
			||||||
prog = re.compile(pat)
 | 
					 | 
				
			||||||
result = prog.match(str)
 | 
					 | 
				
			||||||
\end{verbatim}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
is equivalent to
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{verbatim}
 | 
					 | 
				
			||||||
result = re.match(pat, str)
 | 
					 | 
				
			||||||
\end{verbatim}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
but the version using \function{compile()} is more efficient when the
 | 
					 | 
				
			||||||
expression will be used several times in a single program.
 | 
					 | 
				
			||||||
%(The compiled version of the last pattern passed to
 | 
					 | 
				
			||||||
%\function{regex.match()} or \function{regex.search()} is cached, so
 | 
					 | 
				
			||||||
%programs that use only a single regular expression at a time needn't
 | 
					 | 
				
			||||||
%worry about compiling regular expressions.)
 | 
					 | 
				
			||||||
\end{funcdesc}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{escape}{string}
 | 
					\begin{funcdesc}{escape}{string}
 | 
				
			||||||
  Return \var{string} with all non-alphanumerics backslashed; this is
 | 
					  Return \var{string} with all non-alphanumerics backslashed; this is
 | 
				
			||||||
  useful if you want to match an arbitrary literal string that may have
 | 
					  useful if you want to match an arbitrary literal string that may have
 | 
				
			||||||
| 
						 | 
					@ -448,8 +449,8 @@ Perform the same operation as \function{sub()}, but return a tuple
 | 
				
			||||||
Compiled regular expression objects support the following methods and
 | 
					Compiled regular expression objects support the following methods and
 | 
				
			||||||
attributes:
 | 
					attributes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\setindexsubitem{(re method)}
 | 
					\begin{methoddesc}[RegexObject]{match}{string\optional{, pos}\optional{,
 | 
				
			||||||
\begin{funcdesc}{match}{string\optional{, pos}\optional{, endpos}}
 | 
					                                       endpos}}
 | 
				
			||||||
  If zero or more characters at the beginning of \var{string} match
 | 
					  If zero or more characters at the beginning of \var{string} match
 | 
				
			||||||
  this regular expression, return a corresponding
 | 
					  this regular expression, return a corresponding
 | 
				
			||||||
  \class{MatchObject} instance.  Return \code{None} if the string does not
 | 
					  \class{MatchObject} instance.  Return \code{None} if the string does not
 | 
				
			||||||
| 
						 | 
					@ -465,9 +466,10 @@ attributes:
 | 
				
			||||||
  be searched; it will be as if the string is \var{endpos} characters
 | 
					  be searched; it will be as if the string is \var{endpos} characters
 | 
				
			||||||
  long, so only the characters from \var{pos} to \var{endpos} will be
 | 
					  long, so only the characters from \var{pos} to \var{endpos} will be
 | 
				
			||||||
  searched for a match.
 | 
					  searched for a match.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{search}{string\optional{, pos}\optional{, endpos}}
 | 
					\begin{methoddesc}[RegexObject]{search}{string\optional{, pos}\optional{,
 | 
				
			||||||
 | 
					                                        endpos}}
 | 
				
			||||||
  Scan through \var{string} looking for a location where this regular
 | 
					  Scan through \var{string} looking for a location where this regular
 | 
				
			||||||
  expression produces a match.  Return \code{None} if no
 | 
					  expression produces a match.  Return \code{None} if no
 | 
				
			||||||
  position in the string matches the pattern; note that this is
 | 
					  position in the string matches the pattern; note that this is
 | 
				
			||||||
| 
						 | 
					@ -475,42 +477,43 @@ attributes:
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  The optional \var{pos} and \var{endpos} parameters have the same
 | 
					  The optional \var{pos} and \var{endpos} parameters have the same
 | 
				
			||||||
  meaning as for the \method{match()} method.
 | 
					  meaning as for the \method{match()} method.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{split}{string, \optional{, maxsplit\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{split}{string, \optional{,
 | 
				
			||||||
 | 
					                                       maxsplit\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{split()} function, using the compiled pattern.
 | 
					Identical to the \function{split()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{sub}{repl, string\optional{, count\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{sub}{repl, string\optional{, count\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{sub()} function, using the compiled pattern.
 | 
					Identical to the \function{sub()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{subn}{repl, string\optional{, count\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{subn}{repl, string\optional{,
 | 
				
			||||||
 | 
					                                      count\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{subn()} function, using the compiled pattern.
 | 
					Identical to the \function{subn()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\setindexsubitem{(regex attribute)}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{flags}
 | 
					\begin{memberdesc}[RegexObject]{flags}
 | 
				
			||||||
The flags argument used when the regex object was compiled, or
 | 
					The flags argument used when the regex object was compiled, or
 | 
				
			||||||
\code{0} if no flags were provided.
 | 
					\code{0} if no flags were provided.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{groupindex}
 | 
					\begin{memberdesc}[RegexObject]{groupindex}
 | 
				
			||||||
A dictionary mapping any symbolic group names defined by 
 | 
					A dictionary mapping any symbolic group names defined by 
 | 
				
			||||||
\code{(?P<\var{id}>)} to group numbers.  The dictionary is empty if no
 | 
					\code{(?P<\var{id}>)} to group numbers.  The dictionary is empty if no
 | 
				
			||||||
symbolic groups were used in the pattern.
 | 
					symbolic groups were used in the pattern.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{pattern}
 | 
					\begin{memberdesc}[RegexObject]{pattern}
 | 
				
			||||||
The pattern string from which the regex object was compiled.
 | 
					The pattern string from which the regex object was compiled.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\subsection{Match Objects}
 | 
					\subsection{Match Objects}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\class{MatchObject} instances support the following methods and attributes:
 | 
					\class{MatchObject} instances support the following methods and attributes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{group}{\optional{group1, group2, ...}}
 | 
					\begin{methoddesc}[MatchObject]{group}{\optional{group1, group2, ...}}
 | 
				
			||||||
Returns one or more subgroups of the match.  If there is a single
 | 
					Returns one or more subgroups of the match.  If there is a single
 | 
				
			||||||
argument, the result is a single string; if there are
 | 
					argument, the result is a single string; if there are
 | 
				
			||||||
multiple arguments, the result is a tuple with one item per argument.
 | 
					multiple arguments, the result is a tuple with one item per argument.
 | 
				
			||||||
| 
						 | 
					@ -534,18 +537,18 @@ m = re.match(r"(?P<int>\d+)\.(\d*)", '3.14')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
After performing this match, \code{m.group(1)} is \code{'3'}, as is
 | 
					After performing this match, \code{m.group(1)} is \code{'3'}, as is
 | 
				
			||||||
\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
 | 
					\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{groups}{}
 | 
					\begin{methoddesc}[MatchObject]{groups}{}
 | 
				
			||||||
Return a tuple containing all the subgroups of the match, from 1 up to
 | 
					Return a tuple containing all the subgroups of the match, from 1 up to
 | 
				
			||||||
however many groups are in the pattern.  Groups that did not
 | 
					however many groups are in the pattern.  Groups that did not
 | 
				
			||||||
participate in the match have values of \code{None}.  (Incompatibility 
 | 
					participate in the match have values of \code{None}.  (Incompatibility 
 | 
				
			||||||
note: in the original Python 1.5 release, if the tuple was one element
 | 
					note: in the original Python 1.5 release, if the tuple was one element
 | 
				
			||||||
long, a string would be returned instead.  In later versions, a
 | 
					long, a string would be returned instead.  In later versions, a
 | 
				
			||||||
singleton tuple is returned in such cases.)
 | 
					singleton tuple is returned in such cases.)
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{start}{\optional{group}}
 | 
					\begin{methoddesc}[MatchObject]{start}{\optional{group}}
 | 
				
			||||||
\funcline{end}{\optional{group}}
 | 
					\funcline{end}{\optional{group}}
 | 
				
			||||||
Return the indices of the start and end of the substring
 | 
					Return the indices of the start and end of the substring
 | 
				
			||||||
matched by \var{group}; \var{group} defaults to zero (meaning the whole
 | 
					matched by \var{group}; \var{group} defaults to zero (meaning the whole
 | 
				
			||||||
| 
						 | 
					@ -567,36 +570,35 @@ re.search('b(c?)', 'cba')}, \code{\var{m}.start(0)} is 1,
 | 
				
			||||||
\code{\var{m}.end(0)} is 2, \code{\var{m}.start(1)} and
 | 
					\code{\var{m}.end(0)} is 2, \code{\var{m}.start(1)} and
 | 
				
			||||||
\code{\var{m}.end(1)} are both 2, and \code{\var{m}.start(2)} raises
 | 
					\code{\var{m}.end(1)} are both 2, and \code{\var{m}.start(2)} raises
 | 
				
			||||||
an \exception{IndexError} exception.
 | 
					an \exception{IndexError} exception.
 | 
				
			||||||
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\end{funcdesc}
 | 
					\begin{methoddesc}[MatchObject]{span}{\optional{group}}
 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{span}{\optional{group}}
 | 
					 | 
				
			||||||
For \class{MatchObject} \var{m}, return the 2-tuple
 | 
					For \class{MatchObject} \var{m}, return the 2-tuple
 | 
				
			||||||
\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
 | 
					\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
 | 
				
			||||||
Note that if \var{group} did not contribute to the match, this is
 | 
					Note that if \var{group} did not contribute to the match, this is
 | 
				
			||||||
\code{(None, None)}.  Again, \var{group} defaults to zero.
 | 
					\code{(None, None)}.  Again, \var{group} defaults to zero.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{pos}
 | 
					\begin{memberdesc}[MatchObject]{pos}
 | 
				
			||||||
The value of \var{pos} which was passed to the
 | 
					The value of \var{pos} which was passed to the
 | 
				
			||||||
\function{search()} or \function{match()} function.  This is the index into
 | 
					\function{search()} or \function{match()} function.  This is the index into
 | 
				
			||||||
the string at which the regex engine started looking for a match. 
 | 
					the string at which the regex engine started looking for a match. 
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{endpos}
 | 
					\begin{memberdesc}[MatchObject]{endpos}
 | 
				
			||||||
The value of \var{endpos} which was passed to the
 | 
					The value of \var{endpos} which was passed to the
 | 
				
			||||||
\function{search()} or \function{match()} function.  This is the index into
 | 
					\function{search()} or \function{match()} function.  This is the index into
 | 
				
			||||||
the string beyond which the regex engine will not go.
 | 
					the string beyond which the regex engine will not go.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{re}
 | 
					\begin{memberdesc}[MatchObject]{re}
 | 
				
			||||||
The regular expression object whose \method{match()} or
 | 
					The regular expression object whose \method{match()} or
 | 
				
			||||||
\method{search()} method produced this \class{MatchObject} instance.
 | 
					\method{search()} method produced this \class{MatchObject} instance.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{string}
 | 
					\begin{memberdesc}[MatchObject]{string}
 | 
				
			||||||
The string passed to \function{match()} or \function{search()}.
 | 
					The string passed to \function{match()} or \function{search()}.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{seealso}
 | 
					\begin{seealso}
 | 
				
			||||||
\seetext{Jeffrey Friedl, \emph{Mastering Regular Expressions},
 | 
					\seetext{Jeffrey Friedl, \emph{Mastering Regular Expressions},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										116
									
								
								Doc/libre.tex
									
										
									
									
									
								
							
							
						
						
									
										116
									
								
								Doc/libre.tex
									
										
									
									
									
								
							| 
						 | 
					@ -126,7 +126,8 @@ simplest expressions.
 | 
				
			||||||
be listed individually, or a range of characters can be indicated by
 | 
					be listed individually, or a range of characters can be indicated by
 | 
				
			||||||
giving two characters and separating them by a '-'.  Special
 | 
					giving two characters and separating them by a '-'.  Special
 | 
				
			||||||
characters are not active inside sets.  For example, \code{[akm\$]}
 | 
					characters are not active inside sets.  For example, \code{[akm\$]}
 | 
				
			||||||
will match any of the characters 'a', 'k', 'm', or '\$'; \code{[a-z]}
 | 
					will match any of the characters \character{a}, \character{k},
 | 
				
			||||||
 | 
					\character{m}, or \character{\$}; \code{[a-z]}
 | 
				
			||||||
will match any lowercase letter and \code{[a-zA-Z0-9]} matches any
 | 
					will match any lowercase letter and \code{[a-zA-Z0-9]} matches any
 | 
				
			||||||
letter or digit.  Character classes such as \code{\e w} or \code {\e
 | 
					letter or digit.  Character classes such as \code{\e w} or \code {\e
 | 
				
			||||||
S} (defined below) are also acceptable inside a range.  If you want to
 | 
					S} (defined below) are also acceptable inside a range.  If you want to
 | 
				
			||||||
| 
						 | 
					@ -278,6 +279,27 @@ The module defines the following functions and constants, and an exception:
 | 
				
			||||||
  \var{flags} value.  Values can be any of the following variables,
 | 
					  \var{flags} value.  Values can be any of the following variables,
 | 
				
			||||||
  combined using bitwise OR (the \code{|} operator).
 | 
					  combined using bitwise OR (the \code{|} operator).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The sequence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{verbatim}
 | 
				
			||||||
 | 
					prog = re.compile(pat)
 | 
				
			||||||
 | 
					result = prog.match(str)
 | 
				
			||||||
 | 
					\end{verbatim}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					is equivalent to
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{verbatim}
 | 
				
			||||||
 | 
					result = re.match(pat, str)
 | 
				
			||||||
 | 
					\end{verbatim}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					but the version using \function{compile()} is more efficient when the
 | 
				
			||||||
 | 
					expression will be used several times in a single program.
 | 
				
			||||||
 | 
					%(The compiled version of the last pattern passed to
 | 
				
			||||||
 | 
					%\function{regex.match()} or \function{regex.search()} is cached, so
 | 
				
			||||||
 | 
					%programs that use only a single regular expression at a time needn't
 | 
				
			||||||
 | 
					%worry about compiling regular expressions.)
 | 
				
			||||||
 | 
					\end{funcdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{I}
 | 
					\begin{datadesc}{I}
 | 
				
			||||||
\dataline{IGNORECASE}
 | 
					\dataline{IGNORECASE}
 | 
				
			||||||
Perform case-insensitive matching; expressions like \code{[A-Z]} will match
 | 
					Perform case-insensitive matching; expressions like \code{[A-Z]} will match
 | 
				
			||||||
| 
						 | 
					@ -319,27 +341,6 @@ leftmost such \code{\#} through the end of the line are ignored.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{datadesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The sequence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{verbatim}
 | 
					 | 
				
			||||||
prog = re.compile(pat)
 | 
					 | 
				
			||||||
result = prog.match(str)
 | 
					 | 
				
			||||||
\end{verbatim}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
is equivalent to
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{verbatim}
 | 
					 | 
				
			||||||
result = re.match(pat, str)
 | 
					 | 
				
			||||||
\end{verbatim}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
but the version using \function{compile()} is more efficient when the
 | 
					 | 
				
			||||||
expression will be used several times in a single program.
 | 
					 | 
				
			||||||
%(The compiled version of the last pattern passed to
 | 
					 | 
				
			||||||
%\function{regex.match()} or \function{regex.search()} is cached, so
 | 
					 | 
				
			||||||
%programs that use only a single regular expression at a time needn't
 | 
					 | 
				
			||||||
%worry about compiling regular expressions.)
 | 
					 | 
				
			||||||
\end{funcdesc}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{escape}{string}
 | 
					\begin{funcdesc}{escape}{string}
 | 
				
			||||||
  Return \var{string} with all non-alphanumerics backslashed; this is
 | 
					  Return \var{string} with all non-alphanumerics backslashed; this is
 | 
				
			||||||
  useful if you want to match an arbitrary literal string that may have
 | 
					  useful if you want to match an arbitrary literal string that may have
 | 
				
			||||||
| 
						 | 
					@ -448,8 +449,8 @@ Perform the same operation as \function{sub()}, but return a tuple
 | 
				
			||||||
Compiled regular expression objects support the following methods and
 | 
					Compiled regular expression objects support the following methods and
 | 
				
			||||||
attributes:
 | 
					attributes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\setindexsubitem{(re method)}
 | 
					\begin{methoddesc}[RegexObject]{match}{string\optional{, pos}\optional{,
 | 
				
			||||||
\begin{funcdesc}{match}{string\optional{, pos}\optional{, endpos}}
 | 
					                                       endpos}}
 | 
				
			||||||
  If zero or more characters at the beginning of \var{string} match
 | 
					  If zero or more characters at the beginning of \var{string} match
 | 
				
			||||||
  this regular expression, return a corresponding
 | 
					  this regular expression, return a corresponding
 | 
				
			||||||
  \class{MatchObject} instance.  Return \code{None} if the string does not
 | 
					  \class{MatchObject} instance.  Return \code{None} if the string does not
 | 
				
			||||||
| 
						 | 
					@ -465,9 +466,10 @@ attributes:
 | 
				
			||||||
  be searched; it will be as if the string is \var{endpos} characters
 | 
					  be searched; it will be as if the string is \var{endpos} characters
 | 
				
			||||||
  long, so only the characters from \var{pos} to \var{endpos} will be
 | 
					  long, so only the characters from \var{pos} to \var{endpos} will be
 | 
				
			||||||
  searched for a match.
 | 
					  searched for a match.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{search}{string\optional{, pos}\optional{, endpos}}
 | 
					\begin{methoddesc}[RegexObject]{search}{string\optional{, pos}\optional{,
 | 
				
			||||||
 | 
					                                        endpos}}
 | 
				
			||||||
  Scan through \var{string} looking for a location where this regular
 | 
					  Scan through \var{string} looking for a location where this regular
 | 
				
			||||||
  expression produces a match.  Return \code{None} if no
 | 
					  expression produces a match.  Return \code{None} if no
 | 
				
			||||||
  position in the string matches the pattern; note that this is
 | 
					  position in the string matches the pattern; note that this is
 | 
				
			||||||
| 
						 | 
					@ -475,42 +477,43 @@ attributes:
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  The optional \var{pos} and \var{endpos} parameters have the same
 | 
					  The optional \var{pos} and \var{endpos} parameters have the same
 | 
				
			||||||
  meaning as for the \method{match()} method.
 | 
					  meaning as for the \method{match()} method.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{split}{string, \optional{, maxsplit\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{split}{string, \optional{,
 | 
				
			||||||
 | 
					                                       maxsplit\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{split()} function, using the compiled pattern.
 | 
					Identical to the \function{split()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{sub}{repl, string\optional{, count\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{sub}{repl, string\optional{, count\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{sub()} function, using the compiled pattern.
 | 
					Identical to the \function{sub()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{subn}{repl, string\optional{, count\code{ = 0}}}
 | 
					\begin{methoddesc}[RegexObject]{subn}{repl, string\optional{,
 | 
				
			||||||
 | 
					                                      count\code{ = 0}}}
 | 
				
			||||||
Identical to the \function{subn()} function, using the compiled pattern.
 | 
					Identical to the \function{subn()} function, using the compiled pattern.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\setindexsubitem{(regex attribute)}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{flags}
 | 
					\begin{memberdesc}[RegexObject]{flags}
 | 
				
			||||||
The flags argument used when the regex object was compiled, or
 | 
					The flags argument used when the regex object was compiled, or
 | 
				
			||||||
\code{0} if no flags were provided.
 | 
					\code{0} if no flags were provided.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{groupindex}
 | 
					\begin{memberdesc}[RegexObject]{groupindex}
 | 
				
			||||||
A dictionary mapping any symbolic group names defined by 
 | 
					A dictionary mapping any symbolic group names defined by 
 | 
				
			||||||
\code{(?P<\var{id}>)} to group numbers.  The dictionary is empty if no
 | 
					\code{(?P<\var{id}>)} to group numbers.  The dictionary is empty if no
 | 
				
			||||||
symbolic groups were used in the pattern.
 | 
					symbolic groups were used in the pattern.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{pattern}
 | 
					\begin{memberdesc}[RegexObject]{pattern}
 | 
				
			||||||
The pattern string from which the regex object was compiled.
 | 
					The pattern string from which the regex object was compiled.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\subsection{Match Objects}
 | 
					\subsection{Match Objects}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\class{MatchObject} instances support the following methods and attributes:
 | 
					\class{MatchObject} instances support the following methods and attributes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{group}{\optional{group1, group2, ...}}
 | 
					\begin{methoddesc}[MatchObject]{group}{\optional{group1, group2, ...}}
 | 
				
			||||||
Returns one or more subgroups of the match.  If there is a single
 | 
					Returns one or more subgroups of the match.  If there is a single
 | 
				
			||||||
argument, the result is a single string; if there are
 | 
					argument, the result is a single string; if there are
 | 
				
			||||||
multiple arguments, the result is a tuple with one item per argument.
 | 
					multiple arguments, the result is a tuple with one item per argument.
 | 
				
			||||||
| 
						 | 
					@ -534,18 +537,18 @@ m = re.match(r"(?P<int>\d+)\.(\d*)", '3.14')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
After performing this match, \code{m.group(1)} is \code{'3'}, as is
 | 
					After performing this match, \code{m.group(1)} is \code{'3'}, as is
 | 
				
			||||||
\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
 | 
					\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{groups}{}
 | 
					\begin{methoddesc}[MatchObject]{groups}{}
 | 
				
			||||||
Return a tuple containing all the subgroups of the match, from 1 up to
 | 
					Return a tuple containing all the subgroups of the match, from 1 up to
 | 
				
			||||||
however many groups are in the pattern.  Groups that did not
 | 
					however many groups are in the pattern.  Groups that did not
 | 
				
			||||||
participate in the match have values of \code{None}.  (Incompatibility 
 | 
					participate in the match have values of \code{None}.  (Incompatibility 
 | 
				
			||||||
note: in the original Python 1.5 release, if the tuple was one element
 | 
					note: in the original Python 1.5 release, if the tuple was one element
 | 
				
			||||||
long, a string would be returned instead.  In later versions, a
 | 
					long, a string would be returned instead.  In later versions, a
 | 
				
			||||||
singleton tuple is returned in such cases.)
 | 
					singleton tuple is returned in such cases.)
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{funcdesc}{start}{\optional{group}}
 | 
					\begin{methoddesc}[MatchObject]{start}{\optional{group}}
 | 
				
			||||||
\funcline{end}{\optional{group}}
 | 
					\funcline{end}{\optional{group}}
 | 
				
			||||||
Return the indices of the start and end of the substring
 | 
					Return the indices of the start and end of the substring
 | 
				
			||||||
matched by \var{group}; \var{group} defaults to zero (meaning the whole
 | 
					matched by \var{group}; \var{group} defaults to zero (meaning the whole
 | 
				
			||||||
| 
						 | 
					@ -567,36 +570,35 @@ re.search('b(c?)', 'cba')}, \code{\var{m}.start(0)} is 1,
 | 
				
			||||||
\code{\var{m}.end(0)} is 2, \code{\var{m}.start(1)} and
 | 
					\code{\var{m}.end(0)} is 2, \code{\var{m}.start(1)} and
 | 
				
			||||||
\code{\var{m}.end(1)} are both 2, and \code{\var{m}.start(2)} raises
 | 
					\code{\var{m}.end(1)} are both 2, and \code{\var{m}.start(2)} raises
 | 
				
			||||||
an \exception{IndexError} exception.
 | 
					an \exception{IndexError} exception.
 | 
				
			||||||
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\end{funcdesc}
 | 
					\begin{methoddesc}[MatchObject]{span}{\optional{group}}
 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{span}{\optional{group}}
 | 
					 | 
				
			||||||
For \class{MatchObject} \var{m}, return the 2-tuple
 | 
					For \class{MatchObject} \var{m}, return the 2-tuple
 | 
				
			||||||
\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
 | 
					\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
 | 
				
			||||||
Note that if \var{group} did not contribute to the match, this is
 | 
					Note that if \var{group} did not contribute to the match, this is
 | 
				
			||||||
\code{(None, None)}.  Again, \var{group} defaults to zero.
 | 
					\code{(None, None)}.  Again, \var{group} defaults to zero.
 | 
				
			||||||
\end{funcdesc}
 | 
					\end{methoddesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{pos}
 | 
					\begin{memberdesc}[MatchObject]{pos}
 | 
				
			||||||
The value of \var{pos} which was passed to the
 | 
					The value of \var{pos} which was passed to the
 | 
				
			||||||
\function{search()} or \function{match()} function.  This is the index into
 | 
					\function{search()} or \function{match()} function.  This is the index into
 | 
				
			||||||
the string at which the regex engine started looking for a match. 
 | 
					the string at which the regex engine started looking for a match. 
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{endpos}
 | 
					\begin{memberdesc}[MatchObject]{endpos}
 | 
				
			||||||
The value of \var{endpos} which was passed to the
 | 
					The value of \var{endpos} which was passed to the
 | 
				
			||||||
\function{search()} or \function{match()} function.  This is the index into
 | 
					\function{search()} or \function{match()} function.  This is the index into
 | 
				
			||||||
the string beyond which the regex engine will not go.
 | 
					the string beyond which the regex engine will not go.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{re}
 | 
					\begin{memberdesc}[MatchObject]{re}
 | 
				
			||||||
The regular expression object whose \method{match()} or
 | 
					The regular expression object whose \method{match()} or
 | 
				
			||||||
\method{search()} method produced this \class{MatchObject} instance.
 | 
					\method{search()} method produced this \class{MatchObject} instance.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{datadesc}{string}
 | 
					\begin{memberdesc}[MatchObject]{string}
 | 
				
			||||||
The string passed to \function{match()} or \function{search()}.
 | 
					The string passed to \function{match()} or \function{search()}.
 | 
				
			||||||
\end{datadesc}
 | 
					\end{memberdesc}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{seealso}
 | 
					\begin{seealso}
 | 
				
			||||||
\seetext{Jeffrey Friedl, \emph{Mastering Regular Expressions},
 | 
					\seetext{Jeffrey Friedl, \emph{Mastering Regular Expressions},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue