Xbasic

REGEX_ESCAPE Function

Syntax

Formatted_String as C = regex_escape(C text )

Arguments

Formatted_String

Reformatted character data that will properly process in the REGEX functions.

text

Character data including characters that have special meaning in the REGEX functions.

Description

Escapes characters that have special meaning in Regular Expressions

Discussion

The REGEX_ESCAPE() function processes a text string and escapes any characters that have special meaning within a regular expression. This is useful when passing text, not an expression, into the REGEX functions

Example 

For example, lets replace the letter "a" in "Alpha Software" with "(b)".

? regex_merge("Alpha Software", "a", "(b)")
= "Alphb Softwbre"

The replacement above was not quite right because the "(" and ")" were not included as Part of the replacement. They are two of the characters that have special meaning in regular expressions and need to be escaped:

? regex_merge("Alpha Software", "a", regex_escape("(b)"))
= "Alph(b) Softw(b)re"

See Also