Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4650392

Browse files
committed
Various updates to the effect that the group argument is always optional.
Also documented that groups() now always returns a tuple.
1 parent 7d4ecb8 commit 4650392

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

Doc/lib/libre.tex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,20 @@ \subsection{Match Objects}
490490

491491
\code{MatchObject} instances support the following methods and attributes:
492492

493-
\begin{funcdesc}{group}{\optional{g1, g2, ...}}
494-
Returns one or more groups of the match. If there is a single
495-
\var{index} argument, the result is a single string; if there are
493+
\begin{funcdesc}{group}{\optional{group1, group2, ...}}
494+
Returns one or more subgroups of the match. If there is a single
495+
argument, the result is a single string; if there are
496496
multiple arguments, the result is a tuple with one item per argument.
497-
If the \var{index} is zero, the corresponding return value is the
497+
Without arguments, \var{group1} defaults to zero (i.e. the whole match
498+
is returned).
499+
If a \var{groupN} argument is zero, the corresponding return value is the
498500
entire matching string; if it is in the inclusive range [1..99], it is
499501
the string matching the the corresponding parenthesized group. If no
500502
such group exists, the corresponding result is
501503
\code{None}.
502504

503505
If the regular expression uses the \code{(?P<\var{name}>...)} syntax,
504-
the \var{index} arguments may also be strings identifying groups by
506+
the \var{groupN} arguments may also be strings identifying groups by
505507
their group name.
506508

507509
A moderately complicated example:
@@ -511,7 +513,7 @@ \subsection{Match Objects}
511513
\end{verbatim}
512514

513515
After performing this match, \code{m.group(1)} is \code{'3'}, as is
514-
\code{m.group('int')}. \code{m.group(2)} is \code{'14'}.
516+
\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
515517
\end{funcdesc}
516518

517519
\begin{funcdesc}{groups}{}
@@ -523,12 +525,14 @@ \subsection{Match Objects}
523525
singleton tuple is returned in such cases.)
524526
\end{funcdesc}
525527

526-
\begin{funcdesc}{start}{group}
528+
\begin{funcdesc}{start}{\optional{group}}
527529
\end{funcdesc}
528530

529-
\begin{funcdesc}{end}{group}
531+
\begin{funcdesc}{end}{\optional{group}}
530532
Return the indices of the start and end of the substring
531-
matched by \var{group}. Return \code{None} if \var{group} exists but
533+
matched by \var{group}; \var{group} defaults to zero (meaning the whole
534+
matched substring).
535+
Return \code{None} if \var{group} exists but
532536
did not contribute to the match. For a match object
533537
\var{m}, and a group \var{g} that did contribute to the match, the
534538
substring matched by group \var{g} (equivalent to
@@ -548,11 +552,11 @@ \subsection{Match Objects}
548552

549553
\end{funcdesc}
550554

551-
\begin{funcdesc}{span}{group}
555+
\begin{funcdesc}{span}{\optional{group}}
552556
For \code{MatchObject} \var{m}, return the 2-tuple
553557
\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
554558
Note that if \var{group} did not contribute to the match, this is
555-
\code{(None, None)}.
559+
\code{(None, None)}. Again, \var{group} defaults to zero.
556560
\end{funcdesc}
557561

558562
\begin{datadesc}{pos}

Doc/libre.tex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,20 @@ \subsection{Match Objects}
490490

491491
\code{MatchObject} instances support the following methods and attributes:
492492

493-
\begin{funcdesc}{group}{\optional{g1, g2, ...}}
494-
Returns one or more groups of the match. If there is a single
495-
\var{index} argument, the result is a single string; if there are
493+
\begin{funcdesc}{group}{\optional{group1, group2, ...}}
494+
Returns one or more subgroups of the match. If there is a single
495+
argument, the result is a single string; if there are
496496
multiple arguments, the result is a tuple with one item per argument.
497-
If the \var{index} is zero, the corresponding return value is the
497+
Without arguments, \var{group1} defaults to zero (i.e. the whole match
498+
is returned).
499+
If a \var{groupN} argument is zero, the corresponding return value is the
498500
entire matching string; if it is in the inclusive range [1..99], it is
499501
the string matching the the corresponding parenthesized group. If no
500502
such group exists, the corresponding result is
501503
\code{None}.
502504

503505
If the regular expression uses the \code{(?P<\var{name}>...)} syntax,
504-
the \var{index} arguments may also be strings identifying groups by
506+
the \var{groupN} arguments may also be strings identifying groups by
505507
their group name.
506508

507509
A moderately complicated example:
@@ -511,7 +513,7 @@ \subsection{Match Objects}
511513
\end{verbatim}
512514

513515
After performing this match, \code{m.group(1)} is \code{'3'}, as is
514-
\code{m.group('int')}. \code{m.group(2)} is \code{'14'}.
516+
\code{m.group('int')}, and \code{m.group(2)} is \code{'14'}.
515517
\end{funcdesc}
516518

517519
\begin{funcdesc}{groups}{}
@@ -523,12 +525,14 @@ \subsection{Match Objects}
523525
singleton tuple is returned in such cases.)
524526
\end{funcdesc}
525527

526-
\begin{funcdesc}{start}{group}
528+
\begin{funcdesc}{start}{\optional{group}}
527529
\end{funcdesc}
528530

529-
\begin{funcdesc}{end}{group}
531+
\begin{funcdesc}{end}{\optional{group}}
530532
Return the indices of the start and end of the substring
531-
matched by \var{group}. Return \code{None} if \var{group} exists but
533+
matched by \var{group}; \var{group} defaults to zero (meaning the whole
534+
matched substring).
535+
Return \code{None} if \var{group} exists but
532536
did not contribute to the match. For a match object
533537
\var{m}, and a group \var{g} that did contribute to the match, the
534538
substring matched by group \var{g} (equivalent to
@@ -548,11 +552,11 @@ \subsection{Match Objects}
548552

549553
\end{funcdesc}
550554

551-
\begin{funcdesc}{span}{group}
555+
\begin{funcdesc}{span}{\optional{group}}
552556
For \code{MatchObject} \var{m}, return the 2-tuple
553557
\code{(\var{m}.start(\var{group}), \var{m}.end(\var{group}))}.
554558
Note that if \var{group} did not contribute to the match, this is
555-
\code{(None, None)}.
559+
\code{(None, None)}. Again, \var{group} defaults to zero.
556560
\end{funcdesc}
557561

558562
\begin{datadesc}{pos}

0 commit comments

Comments
 (0)