ReReplace
Uses a regular expression (regex) to search a string for a string pattern and replace it with another.
The search is case-sensitive.
Method Signature
ReReplace(string=[string], regex=[string], substring=[string], scope=[string])
Arguments
Argument
Type
Required
Description
Default
string
string
true
The string to search
regex
string
true
The regular expression to search for
substring
string
true
The string to replace regex with
scope
string
true
The scope to search in (one, all)
one
Examples
Strip Characters Using ReReplace
This example strips out all characters except a-z and 0-9.
reReplaceNoCase( "test 123!", "[^a-z0-9]", "", "ALL" );
Result: test123
Extract Characters Using Back Reference
Uses a back reference: \1 to extract the pattern contained within the parenthesis.
reReplaceNoCase( "123abc456", "[0-9]+([a-z]+)[0-9]+", "\1" );
Result: abc
Additional Examples
writeDump( REReplaceNoCase( "xxabcxxabcxx", "ABC", "def" ) );
writeDump( REReplaceNoCase( "CABARET", "C|B", "G", "ALL" ) );
writeDump( REReplaceNoCase( "cabaret", "[A-Z]", "G", "ALL" ) );
writeDump( REReplaceNoCase( "I love jeLLies", "jell(y|ies)", "cookies" ) );
writeDump( REReplaceNoCase( "I love Jelly", "jell(y|ies)", "cookies" ) );
Related
Last updated
Was this helpful?