2

I have this Javascript pattern

^(\b[A-Z]\w*(\s|\.)*)+$

I tried using it on my XML Schema

<xs:pattern value="^(\b[A-Z][a-z]*(\s|\.)*)+$">

But when I validate I received an error saying InvalidRegex: Pattern value '^(\b[A-Z][a-z](\s|.))+$' is not a valid regular expression. The reported error was: 'This expression is not supported in the current option setting.'.

Is there a way for my Javascript pattern to work on my XML Schema pattern?

1

2 Answers 2

1

Is not always possible to transform JS regex to XSD regex, some things like word-boundary, lookaheads and others are not supported in XSD regex, as mentioned in Michael Kay answer.

Based on your other question asking for a regex to test that all words starts with an uppercase character, you can write another regex valid for XSD, such as this one, that tests that after one (or multiple) spaces or dots the following character should not be a lowercase letter.

([^\s\.]*([\s\.]+[^a-z])?)*[\s\.]*
Sign up to request clarification or add additional context in comments.

Comments

0

Firstly, XSD regular expressions are implicitly anchored to the ends of the string, so you can (and must) omit the "^" and "$".

The more difficult problem is the \b. Outside square brackets, \b in Javascript matches a "word boundary", that is a boundary between a sequence of ASCII letters and digits, and a sequence consisting of non-(ASCII letters and digits).

Looking more carefully, I can't see what the \b actually contributes to your regex, other than ensuring there is at least one character present in the string. As far as I can see, your regex can be simplified to

[A-Za-z\s\.]+ 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.