SPFE Documentation | Collections > SPFE Function Reference > escape-for-regex

Function: escape-for-regex

escape-for-regex(string as item()*) as item()*

Description

Escapes a string value to make it suitable for inclusion in a regular expression as a literal string to be matched.

Return value

Return type: item()*

The string with any characters that are reserved characters in a regular expression replaced by the appropriate escape sequence.

Source file

$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl

Parameters

string

Type: item()*

The string to be escaped for use in a regular expression.

Definition

            <xsl:function name="sf:escape-for-regex">
		               <xsl:param name="string"/>
		               <xsl:value-of select="replace($string, '([\\\|\.\?\*\+\(\)\{\}\[\]\$\^\-])', '\\$1')"/>
               
	</xsl:function>