XSLT Error Reference

FORX0002

XSLT 2.0+ function error
Error message
Invalid regular expression / Error at character N in regular expression

The pattern given to matches(), replace(), tokenize() or xsl:analyze-string is not a valid XPath regular expression — watch out for curly braces in attributes and unsupported constructs.

What it means

XPath regular expressions are based on XML Schema regex with a few additions — they are not PCRE/JavaScript regex. FORX0002 means the pattern itself failed to parse.

Common causes

  1. Curly braces inside xsl:analyze-string’s regex attribute. That attribute is an attribute value template, so { and } are AVT delimiters and must be doubled:
<!-- Before: FORX0002 — { interpreted as AVT -->
<xsl:analyze-string select="." regex="\d{3}">

<!-- After: double the braces -->
<xsl:analyze-string select="." regex="\d{{3}}">
  1. Unsupported constructs. XPath regex has no lookahead/lookbehind ((?=, (?<=), no backreferences in matches() patterns’ character classes, no \b word boundary. Rework the pattern (often with tokenize() + predicates).
  2. A lone \ or trailing escapereplace($s, '\', '/') is invalid; escape it: '\\'.
  3. Invalid flags — only s, m, i, x (and q in 3.0) are allowed.

How to fix it

Test the expression interactively: paste a minimal matches() call in XSLT Playground and iterate until the pattern parses. See replace(), tokenize() and matches() for the supported syntax.