Skip to content Skip to sidebar Skip to footer

Javascript Regex To Xml Schema Regex

I have this Javascript pattern ^(\b[A-Z]\w*(\s|\.)*)+$ I tried using it on my XML Schema But when I validate I received an e

Solution 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\.]*

Solution 2:

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\.]+ 

Post a Comment for "Javascript Regex To Xml Schema Regex"