XSLT Error Reference
FORX0002
Error message
Invalid regular expression / Error at character N in regular expressionThe 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
- Curly braces inside
xsl:analyze-string’sregexattribute. 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}}">
- Unsupported constructs. XPath regex has no lookahead/lookbehind (
(?=,(?<=), no backreferences inmatches()patterns’ character classes, no\bword boundary. Rework the pattern (often withtokenize()+ predicates). - A lone
\or trailing escape —replace($s, '\', '/')is invalid; escape it:'\\'. - Invalid flags — only
s,m,i,x(andqin 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.