1 \section{Standard Module
\sectcode{regsub
}}
4 This module defines a number of functions useful for working with
5 regular expressions (see built-in module
\code{regex
}).
7 \renewcommand{\indexsubitem}{(in module regsub)
}
8 \begin{funcdesc
}{sub
}{pat\, repl\, str
}
9 Replace the first occurrence of pattern
\var{pat
} in string
10 \var{str
} by replacement
\var{repl
}. If the pattern isn't found,
11 the string is returned unchanged. The pattern may be a string or an
12 already compiled pattern. The replacement may contain references
13 \samp{\e \var{digit
}} to subpatterns and escaped backslashes.
16 \begin{funcdesc
}{gsub
}{pat\, repl\, str
}
17 Replace all (non-overlapping) occurrences of pattern
\var{pat
} in
18 string
\var{str
} by replacement
\var{repl
}. The same rules as for
19 \code{sub()
} apply. Empty matches for the pattern are replaced only
20 when not adjacent to a previous match, so e.g.
21 \code{gsub('', '-', 'abc')
} returns
\code{'-a-b-c-'
}.
24 \begin{funcdesc
}{split
}{str\, pat
}
25 Split the string
\var{str
} in fields separated by delimiters matching
26 the pattern
\var{pat
}, and return a list containing the fields. Only
27 non-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'
]}.