Name

[2.0] <xsl:analyze-string>

Allows you to compare a string and a regular expression.

Changes in XSLT 2.0

<xsl:analyze-string> is new to XSLT 2.0.

Category

Instruction.

Required Attributes

select

An XPath expression that defines the string to be analyzed. The expression is converted to a string if necessary.

regex

The regular expression. Regular expressions commonly use curly braces ({ and }), which XSLT interprets as the start and end of an attribute value template. For this reason, any curly braces in a regular expression must be doubled. For example, the regular expression "[0-9]{{5}}" matches a five-digit number, while "[0-9]{5}" matches a one-digit number followed by the number 5.

Note

It is a fatal error if the regular expression matches a zero-length string. See Appendix E for more details.

Optional Attribute

flags

The flags attribute modifies how the regular expression is processed. There are four different flags:

s

Regular expressions are evaluated in what the specs refer to as “dot-all” mode. When this flag is used, the dot operator (.) matches any character. Under normal processing (without the s flag), the dot operator matches any character except the newline character (#xA). This flag is useful when you want to match strings that might include a newline character.

m

Regular expressions are evaulated in multiline mode. By default, the meta-character (^) matches the start of the entire string, while $ matches the end of the entire string. In multiline mode, ^ matches the start of any ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.