Document maxsplit arg for split(), with incompatibility note about 1.5
release bug. Document groups() changed behaviour (now always returns tuple).
This commit is contained in:
parent
2b2b3f9bcb
commit
97546399c7
|
@ -350,16 +350,23 @@ expression will be used several times in a single program.
|
||||||
Split \var{string} by the occurrences of \var{pattern}. If
|
Split \var{string} by the occurrences of \var{pattern}. If
|
||||||
capturing parentheses are used in pattern, then occurrences of
|
capturing parentheses are used in pattern, then occurrences of
|
||||||
patterns or subpatterns are also returned.
|
patterns or subpatterns are also returned.
|
||||||
|
If \var{maxsplit} is nonzero, at most \var{maxsplit} splits
|
||||||
|
occur, and the remainder of the string is returned as the final
|
||||||
|
element of the list. (Incompatibility note: in the original Python
|
||||||
|
1.5 release, \var{maxsplit} was ignored. This has been fixed in
|
||||||
|
later releases.)
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
>>> re.split('[\W]+', 'Words, words, words.')
|
>>> re.split('[\W]+', 'Words, words, words.')
|
||||||
['Words', 'words', 'words', '']
|
['Words', 'words', 'words', '']
|
||||||
>>> re.split('([\W]+)', 'Words, words, words.')
|
>>> re.split('([\W]+)', 'Words, words, words.')
|
||||||
['Words', ', ', 'words', ', ', 'words', '.', '']
|
['Words', ', ', 'words', ', ', 'words', '.', '']
|
||||||
|
>>> re.split('[\W]+', 'Words, words, words.', 1)
|
||||||
|
['Words', 'words, words.']
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}\ecode
|
||||||
%
|
%
|
||||||
This function combines and extends the functionality of
|
This function combines and extends the functionality of
|
||||||
the old \code{regex.split()} and \code{regex.splitx()}.
|
the old \code{regsub.split()} and \code{regsub.splitx()}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{sub}{pattern\, repl\, string\optional{, count=0}}
|
\begin{funcdesc}{sub}{pattern\, repl\, string\optional{, count=0}}
|
||||||
|
@ -499,8 +506,10 @@ After performing this match, \code{m.group(1)} is \code{'3'}, as is \code{m.grou
|
||||||
\begin{funcdesc}{groups}{}
|
\begin{funcdesc}{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}. If the tuple
|
participate in the match have values of \code{None}. (Incompatibility
|
||||||
would only be one element long, a string will be returned instead.
|
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
|
||||||
|
singleton tuple is returned in such cases.)
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{start}{group}
|
\begin{funcdesc}{start}{group}
|
||||||
|
|
|
@ -350,16 +350,23 @@ expression will be used several times in a single program.
|
||||||
Split \var{string} by the occurrences of \var{pattern}. If
|
Split \var{string} by the occurrences of \var{pattern}. If
|
||||||
capturing parentheses are used in pattern, then occurrences of
|
capturing parentheses are used in pattern, then occurrences of
|
||||||
patterns or subpatterns are also returned.
|
patterns or subpatterns are also returned.
|
||||||
|
If \var{maxsplit} is nonzero, at most \var{maxsplit} splits
|
||||||
|
occur, and the remainder of the string is returned as the final
|
||||||
|
element of the list. (Incompatibility note: in the original Python
|
||||||
|
1.5 release, \var{maxsplit} was ignored. This has been fixed in
|
||||||
|
later releases.)
|
||||||
%
|
%
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
>>> re.split('[\W]+', 'Words, words, words.')
|
>>> re.split('[\W]+', 'Words, words, words.')
|
||||||
['Words', 'words', 'words', '']
|
['Words', 'words', 'words', '']
|
||||||
>>> re.split('([\W]+)', 'Words, words, words.')
|
>>> re.split('([\W]+)', 'Words, words, words.')
|
||||||
['Words', ', ', 'words', ', ', 'words', '.', '']
|
['Words', ', ', 'words', ', ', 'words', '.', '']
|
||||||
|
>>> re.split('[\W]+', 'Words, words, words.', 1)
|
||||||
|
['Words', 'words, words.']
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}\ecode
|
||||||
%
|
%
|
||||||
This function combines and extends the functionality of
|
This function combines and extends the functionality of
|
||||||
the old \code{regex.split()} and \code{regex.splitx()}.
|
the old \code{regsub.split()} and \code{regsub.splitx()}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{sub}{pattern\, repl\, string\optional{, count=0}}
|
\begin{funcdesc}{sub}{pattern\, repl\, string\optional{, count=0}}
|
||||||
|
@ -499,8 +506,10 @@ After performing this match, \code{m.group(1)} is \code{'3'}, as is \code{m.grou
|
||||||
\begin{funcdesc}{groups}{}
|
\begin{funcdesc}{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}. If the tuple
|
participate in the match have values of \code{None}. (Incompatibility
|
||||||
would only be one element long, a string will be returned instead.
|
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
|
||||||
|
singleton tuple is returned in such cases.)
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{start}{group}
|
\begin{funcdesc}{start}{group}
|
||||||
|
|
Loading…
Reference in New Issue