[Python-checkins] CVS: python/dist/src/Doc/lib libre.tex,1.62,1.63

Fred L. Drake fdrake@users.sourceforge.net
Thu, 12 Jul 2001 07:13:45 -0700


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv12642/lib

Modified Files:
	libre.tex 
Log Message:

Fix return value for m.group() for groups not in the part of the RE that
matched; reported by Paul Moore.

Wrapped several long lines.


Index: libre.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libre.tex,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -r1.62 -r1.63
*** libre.tex	2001/07/06 20:30:11	1.62
--- libre.tex	2001/07/12 14:13:43	1.63
***************
*** 75,88 ****
  
  Regular expressions can contain both special and ordinary characters.
! Most ordinary characters, like \character{A}, \character{a}, or \character{0},
! are the simplest regular expressions; they simply match themselves.  
! You can concatenate ordinary characters, so \regexp{last} matches the
! string \code{'last'}.  (In the rest of this section, we'll write RE's in
! \regexp{this special style}, usually without quotes, and strings to be
! matched \code{'in single quotes'}.)
! 
! Some characters, like \character{|} or \character{(}, are special.  Special
! characters either stand for classes of ordinary characters, or affect
! how the regular expressions around them are interpreted.
  
  The special characters are:
--- 75,88 ----
  
  Regular expressions can contain both special and ordinary characters.
! Most ordinary characters, like \character{A}, \character{a}, or
! \character{0}, are the simplest regular expressions; they simply match
! themselves.  You can concatenate ordinary characters, so \regexp{last}
! matches the string \code{'last'}.  (In the rest of this section, we'll
! write RE's in \regexp{this special style}, usually without quotes, and
! strings to be matched \code{'in single quotes'}.)
! 
! Some characters, like \character{|} or \character{(}, are special.
! Special characters either stand for classes of ordinary characters, or
! affect how the regular expressions around them are interpreted.
  
  The special characters are:
***************
*** 115,128 ****
  match 0 or 1 repetitions of the preceding RE.  \regexp{ab?} will
  match either 'a' or 'ab'.
- \item[\code{*?}, \code{+?}, \code{??}] The \character{*}, \character{+}, and
- \character{?} qualifiers are all \dfn{greedy}; they match as much text as
- possible.  Sometimes this behaviour isn't desired; if the RE
- \regexp{<.*>} is matched against \code{'<H1>title</H1>'}, it will match the
- entire string, and not just \code{'<H1>'}.
- Adding \character{?} after the qualifier makes it perform the match in
- \dfn{non-greedy} or \dfn{minimal} fashion; as \emph{few} characters as
- possible will be matched.  Using \regexp{.*?} in the previous
- expression will match only \code{'<H1>'}.
  
  \item[\code{\{\var{m},\var{n}\}}] Causes the resulting RE to match from
  \var{m} to \var{n} repetitions of the preceding RE, attempting to
--- 115,129 ----
  match 0 or 1 repetitions of the preceding RE.  \regexp{ab?} will
  match either 'a' or 'ab'.
  
+ \item[\code{*?}, \code{+?}, \code{??}] The \character{*},
+ \character{+}, and \character{?} qualifiers are all \dfn{greedy}; they
+ match as much text as possible.  Sometimes this behaviour isn't
+ desired; if the RE \regexp{<.*>} is matched against
+ \code{'<H1>title</H1>'}, it will match the entire string, and not just
+ \code{'<H1>'}.  Adding \character{?} after the qualifier makes it
+ perform the match in \dfn{non-greedy} or \dfn{minimal} fashion; as
+ \emph{few} characters as possible will be matched.  Using \regexp{.*?}
+ in the previous expression will match only \code{'<H1>'}.
+ 
  \item[\code{\{\var{m},\var{n}\}}] Causes the resulting RE to match from
  \var{m} to \var{n} repetitions of the preceding RE, attempting to
***************
*** 168,175 ****
  
  You can match the characters not within a range by \dfn{complementing}
! the set.  This is indicated by including a
! \character{\^} as the first character of the set; \character{\^} elsewhere will
! simply match the \character{\^} character.  For example, \regexp{[{\^}5]}
! will match any character except \character{5}.
  
  \item[\character{|}]\code{A|B}, where A and B can be arbitrary REs,
--- 169,176 ----
  
  You can match the characters not within a range by \dfn{complementing}
! the set.  This is indicated by including a \character{\^} as the first
! character of the set; \character{\^} elsewhere will simply match the
! \character{\^} character.  For example, \regexp{[{\^}5]} will match
! any character except \character{5}.
  
  \item[\character{|}]\code{A|B}, where A and B can be arbitrary REs,
***************
*** 400,405 ****
  \begin{datadesc}{I}
  \dataline{IGNORECASE}
! Perform case-insensitive matching; expressions like \regexp{[A-Z]} will match
! lowercase letters, too.  This is not affected by the current locale.
  \end{datadesc}
  
--- 401,407 ----
  \begin{datadesc}{I}
  \dataline{IGNORECASE}
! Perform case-insensitive matching; expressions like \regexp{[A-Z]}
! will match lowercase letters, too.  This is not affected by the
! current locale.
  \end{datadesc}
  
***************
*** 415,423 ****
  beginning of the string and at the beginning of each line
  (immediately following each newline); and the pattern character
! \character{\$} matches at the end of the string and at the end of each line
! (immediately preceding each newline).
! By default, \character{\^} matches only at the beginning of the string, and
! \character{\$} only at the end of the string and immediately before the
! newline (if any) at the end of the string. 
  \end{datadesc}
  
--- 417,425 ----
  beginning of the string and at the beginning of each line
  (immediately following each newline); and the pattern character
! \character{\$} matches at the end of the string and at the end of each
! line (immediately preceding each newline).  By default, \character{\^}
! matches only at the beginning of the string, and \character{\$} only
! at the end of the string and immediately before the newline (if any)
! at the end of the string.
  \end{datadesc}
  
***************
*** 441,447 ****
  Whitespace within the pattern is ignored, 
  except when in a character class or preceded by an unescaped
! backslash, and, when a line contains a \character{\#} neither in a character
! class or preceded by an unescaped backslash, all characters from the
! leftmost such \character{\#} through the end of the line are ignored.
  % XXX should add an example here
  \end{datadesc}
--- 443,450 ----
  Whitespace within the pattern is ignored, 
  except when in a character class or preceded by an unescaped
! backslash, and, when a line contains a \character{\#} neither in a
! character class or preceded by an unescaped backslash, all characters
! from the leftmost such \character{\#} through the end of the line are
! ignored.
  % XXX should add an example here
  \end{datadesc}
***************
*** 522,536 ****
  
  The optional argument \var{count} is the maximum number of pattern
! occurrences to be replaced; \var{count} must be a non-negative integer, and
! the default value of 0 means to replace all occurrences.
  
  Empty matches for the pattern are replaced only when not adjacent to a
! previous match, so \samp{sub('x*', '-', 'abc')} returns \code{'-a-b-c-'}.
  
  If \var{repl} is a string, any backslash escapes in it are processed.
  That is, \samp{\e n} is converted to a single newline character,
  \samp{\e r} is converted to a linefeed, and so forth.  Unknown escapes
! such as \samp{\e j} are left alone.  Backreferences, such as \samp{\e 6}, are
! replaced with the substring matched by group 6 in the pattern. 
  
  In addition to character escapes and backreferences as described
--- 525,540 ----
  
  The optional argument \var{count} is the maximum number of pattern
! occurrences to be replaced; \var{count} must be a non-negative
! integer, and the default value of 0 means to replace all occurrences.
  
  Empty matches for the pattern are replaced only when not adjacent to a
! previous match, so \samp{sub('x*', '-', 'abc')} returns
! \code{'-a-b-c-'}.
  
  If \var{repl} is a string, any backslash escapes in it are processed.
  That is, \samp{\e n} is converted to a single newline character,
  \samp{\e r} is converted to a linefeed, and so forth.  Unknown escapes
! such as \samp{\e j} are left alone.  Backreferences, such as \samp{\e
! 6}, are replaced with the substring matched by group 6 in the pattern. 
  
  In addition to character escapes and backreferences as described
***************
*** 642,646 ****
  \subsection{Match Objects \label{match-objects}}
  
! \class{MatchObject} instances support the following methods and attributes:
  
  \begin{methoddesc}[MatchObject]{expand}{template}
--- 646,651 ----
  \subsection{Match Objects \label{match-objects}}
  
! \class{MatchObject} instances support the following methods and
! attributes:
  
  \begin{methoddesc}[MatchObject]{expand}{template}
***************
*** 648,654 ****
  template string \var{template}, as done by the \method{sub()} method.
  Escapes such as \samp{\e n} are converted to the appropriate
! characters, and numeric backreferences (\samp{\e 1}, \samp{\e 2}) and named
! backreferences (\samp{\e g<1>}, \samp{\e g<name>}) are replaced by the contents of the
! corresponding group.
  \end{methoddesc}
  
--- 653,659 ----
  template string \var{template}, as done by the \method{sub()} method.
  Escapes such as \samp{\e n} are converted to the appropriate
! characters, and numeric backreferences (\samp{\e 1}, \samp{\e 2}) and
! named backreferences (\samp{\e g<1>}, \samp{\e g<name>}) are replaced
! by the contents of the corresponding group.
  \end{methoddesc}
  
***************
*** 665,669 ****
  in the pattern, an \exception{IndexError} exception is raised.
  If a group is contained in a part of the pattern that did not match,
! the corresponding result is \code{-1}.  If a group is contained in a 
  part of the pattern that matched multiple times, the last match is
  returned.
--- 670,674 ----
  in the pattern, an \exception{IndexError} exception is raised.
  If a group is contained in a part of the pattern that did not match,
! the corresponding result is \code{None}.  If a group is contained in a 
  part of the pattern that matched multiple times, the last match is
  returned.