O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

[2.0] matches()

Determines whether a given string matches a given regular expression.

Syntax

xs:boolean matches($input as xs:string?, $pattern as xs:string)
xs:boolean matches($input as xs:string?, $pattern as xs:string, 
                   $flags as xs:string)

Inputs

An input string and a regular expression. The matches() function also supports an optional string defining flags that modify how the regular expression is processed.

Outputs

true if the string matches the regular expression; false otherwise.

Regular expressions are extremely powerful, so there are a number of details about how they work:

  • If $input is the empty sequence, it is interpreted as a zero-length string. The matches() function can still return true in this situation. For example, matches((), '.?') is true, as is matches('', '.?').

  • Regular expression matching does not use collations; the characters’ Unicode code points are compared. Cases in which different characters are considered equal in the world’s languages are not taken into account.

  • Unless you use the ^ (start of line) or $ (end of line) characters as anchors in your regular expression, a string is considered a match if any part of it matches the regular expression.

  • Unlike regular expressions used in the <xsl:analyze-string> element, curly braces ({ and }) are not doubled. (Curly braces used inside the regex attribute of <xsl:analyze-string> must be doubled so they aren’t interpreted as attribute value templates.)

  • The $flags parameter modifies how the regular expression is processed. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required