regsub -- Python library reference
Next: struct
Prev: regex
Up: String Services
Top: Top
4.3. Standard Module regsub
This module defines a number of functions useful for working with
regular expressions (see built-in module regex).
- sub (pat, repl, str) -- function of module regsub
-
Replace the first occurrence of pattern pat in string
str by replacement repl. If the pattern isn't found,
the string is returned unchanged. The pattern may be a string or an
already compiled pattern. The replacement may contain references
`\digit' to subpatterns and escaped backslashes.
- gsub (pat, repl, str) -- function of module regsub
-
Replace all (non-overlapping) occurrences of pattern pat in
string str by replacement repl. The same rules as for
sub() apply. Empty matches for the pattern are replaced only
when not adjacent to a previous match, so e.g.
gsub('', '-', 'abc') returns '-a-b-c-'.
- split (str, pat) -- function of module regsub
-
Split the string str in fields separated by delimiters matching
the pattern pat, and return a list containing the fields. Only
non-empty matches for the pattern are considered, so e.g.
split('a:b', ':*') returns ['a', 'b'] and
split('abc', '') returns ['abc'].
Next: struct
Prev: regex
Up: String Services
Top: Top