Description
The functx:escape-for-regex function escapes a string that you wish to be taken literally rather than treated like a regular expression. This is useful when, for example, you are calling the built-in fn:replace function and you want any periods or parentheses to be treated like literal characters rather than regex special characters.
Arguments and Return TypeName | Type | Description |
$arg |
xs:string? |
the string to escape |
return value |
xs:string |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:escape-for-regex" as="xs:string"
xmlns:functx="http://www.functx.com">
<xsl:param name="arg" as="xs:string?"/>
<xsl:sequence select="
replace($arg,
'(\.|\[|\]|\\|\||\-|\^|\$|\?|\*|\+|\{|\}|\(|\))','\\$1')
"/>
</xsl:function>
|
ExamplesXPath Example | Results |
---|
functx:escape-for-regex('5.55') |
5\.55 |
functx:escape-for-regex('[abc]') |
\[abc\] |
See Alsofn:replace | Replaces parts of a string that match a regular expression |
History |
Recommended Reading:
|