1

I have been provided with an XSD I am validating XML against. The XML is failing validation because the XSD is incorrect. I have one field that is meant to allow a 1 - 3 character string. The first character has got to be A, B, C or Z and may optionally be followed by upto 2 characters. I have not had much to do with regular expessions but have tried all manner of combinations to no avail.

The expression supplied is <xs:pattern value="([A,B,C,Z]{1}\w\?{2})"/>

Valid Examples of data are:

B B6 BB AB

Invalid:

G3 A B 6HC

Im sure its a fairly simple expression but I dont seen to be able to get it right!

2 Answers 2

2
[ABCZ]\w{0,2}

No commas in []. {0,2} allows for 0 to 2 word characters. Got rid of the \?, that would match a literal question mark.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks John, I did have this and it is nearly there but it passes A 4 as valid. The space between A and 4 needs to make it invalid.
Sorry John, I have been checking the expressions on an online RegEx checker seems Im either reading the results wrong or the checker is passing invalid data. I updated the XSD and rechecked the XML. Worked perfectly. Thanks.
0

It is a kind of the regular expression. Each symbol have its meaning, I think all are trivial to understand except "?", which means the set of character that succeeds with ? have zero or one occurrence (Don't confuse with the * it means zero or many occurrence). http://www.xmlschemareference.com/regularExpression.html

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.