StringTools[RegSub] - perform regular expression substitutions
|
Calling Sequence
|
|
RegSub( pattern, text, template )
|
|
Parameters
|
|
pattern
|
-
|
string; regular expression
|
text
|
-
|
string; text to use
|
template
|
-
|
string; copy as output
|
|
|
|
|
Description
|
|
•
|
The RegSub( pattern, text, template ) function performs regular expression search and replace on text. RegSub tests whether the string text matches the regular expression pattern. If a match occurs, the string template is copied as the output, but substrings can be replaced with the portion of text that matched pattern as follows.
|
|
The substring & is replaced with the portion of text that matched the entire regular expression pattern. If d is a single digit, then the substring \d is replaced with the substring of text matching the d-th parenthesized subexpression of pattern.
|
|
If text does not match pattern, the value FAIL is returned.
|
|
Note: RegSub is a very low-level procedure. For most applications, StringTools[RegSubs] is easier to use.
|
•
|
This function is part of the StringTools package, and so it can be used in the form RegSub(..) only after executing the command with(StringTools). However, it can always be accessed through the long form of the command by using the form StringTools[RegSub](..).
|
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
|
|
Download Help Document
Was this information helpful?