blob: 5747e4f99bb767c5f6de9678fcdab2f14f135b06 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Standard Module \sectcode{regsub}}
2
3\stmodindex{regsub}
4This module defines a number of functions useful for working with
5regular expressions (see built-in module \code{regex}).
6
7\renewcommand{\indexsubitem}{(in module regsub)}
8\begin{funcdesc}{sub}{pat\, repl\, str}
9Replace the first occurrence of pattern \var{pat} in string
10\var{str} by replacement \var{repl}. If the pattern isn't found,
11the string is returned unchanged. The pattern may be a string or an
12already compiled pattern. The replacement may contain references
13\samp{\e \var{digit}} to subpatterns and escaped backslashes.
14\end{funcdesc}
15
16\begin{funcdesc}{gsub}{pat\, repl\, str}
17Replace all (non-overlapping) occurrences of pattern \var{pat} in
18string \var{str} by replacement \var{repl}. The same rules as for
19\code{sub()} apply. Empty matches for the pattern are replaced only
20when not adjacent to a previous match, so e.g.
21\code{gsub('', '-', 'abc')} returns \code{'-a-b-c-'}.
22\end{funcdesc}
23
24\begin{funcdesc}{split}{str\, pat}
25Split the string \var{str} in fields separated by delimiters matching
26the pattern \var{pat}, and return a list containing the fields. Only
27non-empty matches for the pattern are considered, so e.g.
28\code{split('a:b', ':*')} returns \code{['a', 'b']} and
29\code{split('abc', '')} returns \code{['abc']}.
30\end{funcdesc}