Is it possible to use anchors inside a character class? This doesn\'t work:
analyze-string(\'abcd\', \'[\\s^]abcd[\\s$]\')
It looks like <
If you're using analyze-string
as a function, then presumably you're using a 3.0 implementation of either XSLT or XQuery.
In that case, why do you say "non-capturing groups aren't available"? The XPath Functions and Operators 3.0 spec is explicit that "Non-capturing groups are also recognized. These are indicated by the syntax (?:xxxx)."
I believe the answer is no, you can't include ^
and $
as anchors in a []
, only as literal characters. (I've wished you could do that before too.)
However, you could concat a space on the front and back of the string, then just look for \s
as word boundaries and never mind the anchors. E.g.
analyze-string(concat(' ', 'abcd xyz abcd', ' '), '\sabcd\s')
You may also want +
after each \s
, but that's a separate issue.
Using the caret after the first square bracket will negate the character class. It essentially gives you the opposite of what you're looking to do, meaning the character class will match any character that is not in the character class. Negated character classes also match (invisible) line break characters.
You could try doing a negative look-ahead possibly.
(?!\s)