Added a test for the ability to specify a class attribute in Formatter configuration...
[python.git] / Doc / lib / libregsub.tex
blobb41b7004866d560b1c4b1badad11d4577fe75f21
1 \section{\module{regsub} ---
2 String operations using regular expressions}
4 \declaremodule{standard}{regsub}
5 \modulesynopsis{Substitution and splitting operations that use
6 regular expressions. \strong{Obsolete!}}
9 This module defines a number of functions useful for working with
10 regular expressions (see built-in module \refmodule{regex}).
12 Warning: these functions are not thread-safe.
14 \strong{Obsolescence note:}
15 This module is obsolete as of Python version 1.5; it is still being
16 maintained because much existing code still uses it. All new code in
17 need of regular expressions should use the new \refmodule{re} module, which
18 supports the more powerful and regular Perl-style regular expressions.
19 Existing code should be converted. The standard library module
20 \module{reconvert} helps in converting \refmodule{regex} style regular
21 expressions to \refmodule{re} style regular expressions. (For more
22 conversion help, see Andrew Kuchling's\index{Kuchling, Andrew}
23 ``regex-to-re HOWTO'' at
24 \url{http://www.python.org/doc/howto/regex-to-re/}.)
27 \begin{funcdesc}{sub}{pat, repl, str}
28 Replace the first occurrence of pattern \var{pat} in string
29 \var{str} by replacement \var{repl}. If the pattern isn't found,
30 the string is returned unchanged. The pattern may be a string or an
31 already compiled pattern. The replacement may contain references
32 \samp{\e \var{digit}} to subpatterns and escaped backslashes.
33 \end{funcdesc}
35 \begin{funcdesc}{gsub}{pat, repl, str}
36 Replace all (non-overlapping) occurrences of pattern \var{pat} in
37 string \var{str} by replacement \var{repl}. The same rules as for
38 \code{sub()} apply. Empty matches for the pattern are replaced only
39 when not adjacent to a previous match, so e.g.
40 \code{gsub('', '-', 'abc')} returns \code{'-a-b-c-'}.
41 \end{funcdesc}
43 \begin{funcdesc}{split}{str, pat\optional{, maxsplit}}
44 Split the string \var{str} in fields separated by delimiters matching
45 the pattern \var{pat}, and return a list containing the fields. Only
46 non-empty matches for the pattern are considered, so e.g.
47 \code{split('a:b', ':*')} returns \code{['a', 'b']} and
48 \code{split('abc', '')} returns \code{['abc']}. The \var{maxsplit}
49 defaults to 0. If it is nonzero, only \var{maxsplit} number of splits
50 occur, and the remainder of the string is returned as the final
51 element of the list.
52 \end{funcdesc}
54 \begin{funcdesc}{splitx}{str, pat\optional{, maxsplit}}
55 Split the string \var{str} in fields separated by delimiters matching
56 the pattern \var{pat}, and return a list containing the fields as well
57 as the separators. For example, \code{splitx('a:::b', ':*')} returns
58 \code{['a', ':::', 'b']}. Otherwise, this function behaves the same
59 as \code{split}.
60 \end{funcdesc}
62 \begin{funcdesc}{capwords}{s\optional{, pat}}
63 Capitalize words separated by optional pattern \var{pat}. The default
64 pattern uses any characters except letters, digits and underscores as
65 word delimiters. Capitalization is done by changing the first
66 character of each word to upper case.
67 \end{funcdesc}
69 \begin{funcdesc}{clear_cache}{}
70 The regsub module maintains a cache of compiled regular expressions,
71 keyed on the regular expression string and the syntax of the regex
72 module at the time the expression was compiled. This function clears
73 that cache.
74 \end{funcdesc}