regex_subst(X;L;Y;I;Z)
Returns the given string with a particular match (or all matches) of a specified regular expression replaced by a given substring.
Syntax
regex_subst(X;L;Y;I;Z)
Input
Argument | Type | Description |
---|---|---|
X |
text | A valid regular
expression to search for in the string Y |
L |
text | A list of one or more string options. (L may be
omitted.)These options include:
The 'tre' and 'pcre' options refer to the
back-end regex engine used for matching. If both options are specified, or if
neither option is specified, the TRE engine will be used.Note: The
'lit' and 'right' options cannot be used in
conjunction with the 'pcre' option. |
Y |
text | The string within which to search for the regular
expression X A scalar value or the name of a column |
I |
integer | An index corresponding to a particular instance of the regular expression
X within the given string Y The index
A
negative index counts back from the end of the string (i.e.,
An
index of 0 will cause all occurrences of |
Z |
text | The substring to replace a particular occurrence (or all occurrences) of the
regular expression X within the given string Y A scalar value or the name of a column |
Return Value
Returns the text value corresponding to the I
'th match of the regular
expression X
within the string Y
replaced by the string
Z
.
If I
=0, all occurrences of X
within Y
are replaced by Z
.
If Y
is N/A, the result is N/A.
Sample Usage
regex |
options |
string |
index |
newstring |
regex_subst(regex;options;string;index;newstring) |
---|---|---|---|---|---|
'a(b|c|d)' | 'Abracadabra' | 1 | 'QQ' | 'AbrQQadabra' | |
'a(b|c|d)' | 'icase' | 'Abracadabra' | -4 | 'QQ' | 'QQracadabra' |
'a(b|c|d)' | 'icase' | 'Abracadabra' | 0 | 'QQrQQQQQQra' | |
'a(b|c|d)' | '' | 1 | 'QQ' | '' |
Additional Information
- 1010data supports POSIX standard regular expressions. See Regular Expressions for more information.