Regular expression Escape function
The Regular Expression Escape function escapes a string such that it can be used in a regular expression as a literal.
Note: Functions can be written in Legacy Script Language or in
ECMAScript. For details, see Scripts within tests and stubs.
All the examples given in this topic are in Legacy, unless specified
otherwise.
Usage
To interpret a string
literally, for example, as a text string in a regular expression,
escape those string characters by calling the regexEscape()
function.
Calling this function is useful for passing a literal string into
a regular expression.
regexEscape(any_string)
any_string is the string to escape.
Example
The following example
shows the use of the regexEscape()
function. Characters
such as parentheses are metacharacters, which have special meaning
in regular expressions. To use metacharacters literally in a regular
expression, you must escape them by using the regexEscape()
function.
Legacy:
eq (regexEscape("any(textstring)"),"any\\(textstring\\)" )
ECMAScript:
regexEscape("any(textstring)") == "any\\(textstring\\)"