UnicodeRegexReplace (Unicode function)
Replace regex match(es) (Unicode class)
This page is under construction.
Syntax
%outUnicode = unicode:UnicodeRegexReplace( regex, replacement, - [Options= string]) Throws InvalidRegex
Syntax terms
%outUnicode | Unicode | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
unicode | The input Unicode string, to which the regular expression regex is applied. | ||||||||||||
regex | A Unicode string that is interpreted as a regular expression and that is applied to the method object, unicode, to find the one or more substrings matched by regex. | ||||||||||||
replacement | The Unicode string that replaces the substrings of unicode that regex matches. Except when the A option is specified (as described below for the Options argument), you can include markers in the replacement value to indicate where to insert corresponding captured strings — strings matched by capturing groups (parenthesized subexpressions) in regex, if any.
As in Perl, these markers are in the form $n, where n is the number of the capture group, and 1 is the number of the first capture group. n must not be 0 or contain more than 9 digits. If a capturing group makes no matches (is positional, for example), or if there was no nth capture group corresponding to the $n marker in a replacement string, the (literal) value of $n is used in the replacement string instead of the empty string.
The only characters you can escape in a replacement string are dollar sign ( An invalid replacement string results in request cancellation. | ||||||||||||
Options | This optional, name required, parameter is a String of single-letter options, which may be specified in uppercase or lowercase, in any combination, and blank separated or not, as you prefer. For more information about these options, see Common regex options:
|
Usage notes
- It is strongly recommended that you protect your environment from regular expression processing demands on PDL and STBL space by setting, say,
UTABLE LPDLST 3000
andUTABLE LSTBL 9000
. See SOUL programming considerations. - Within a regular expression, characters enclosed by a pair of unescaped parentheses form a "subexpression." A subexpression is a capturing group if the opening parenthesis is not followed by a question mark (?). A capturing group that is nested within a non-capturing subexpression is still a capturing group.
- In Perl, $n markers (
$1
, for example) enclosed in single quotes are treated as literals instead of as "that which was captured by the first capturing parentheses." RegexReplace uses theA
option of the Options argument for this purpose. - Matching of regex may "succeed" but yet match no characters. For example, a quantifier like
?
is allowed by definition to match no characters, though it tries to match one. UnicodeRegexReplace honors such a zero-length match by substituting the specified replacement string at the current position. If the global option is in effect, the regex is then applied again one position to the right in the input string, and again, until the end of the string. The regex9?
globally applied to the stringabc
with a comma-comma (,,) replacement string results in this output string:,,a,,b,,c,,
. - For information about additional methods that support regular expressions, see Regex processing.