EXSLT - regexp:test

Implementer Page: regexp.test.html
Function Package: regexp.test.zip

Function Syntax

boolean regexp:test(string, string, string?)

The regexp:test function returns true if the string given as the first argument matches the regular expression given as the second argument.

The second argument is a regular expression that follows the Javascript regular expression syntax.

The third argument is a string consisting of flags to be used by the test. If a character is present then that flag is true. The flags are:

  • g: global test - has no effect on this function, but is retained for consistency with regexp:match and regexp:replace.
  • i: case insensitive - the regular expression is treated as case insensitive. If this character is not present, then the regular expression is case sensitive.

Implementations

The following XSLT processors support regexp:test:

Implementations of regexp:test are available in the following languages:

Examples

Function

The following example shows how to use the regexp:test function:

Source

<?xml-stylesheet type="text/xsl" href="regexp.test.1.xsl" ?> <a> <c>Is this EXSLT? No. no</c> </a>

Stylesheet

<xsl:import href="regexp.test.msxsl.xsl" /> <xsl:template match="a"> <xsl:apply-templates /> </xsl:template> <xsl:template match="*"> <out> <xsl:value-of select="." /> - <xsl:value-of select="regexp:test(string(.), 'no', 'g', 'yes!!!')" /> <xsl:value-of select="regexp:test(string(.), 'no', 'gi', 'yes!!!')" /> <xsl:apply-templates select="*" /> </out> </xsl:template>

Result

<out>Is this EXSLT? No. no - truetrue</out>

http://www.exslt.org/regexp/functions/test/index.html last modified 2002-11-12