wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Question: Pattern for string in XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Question: Pattern for string in XSD" Watch "Question: Pattern for string in XSD" New topic
Author

Question: Pattern for string in XSD

Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
Hello,
I want to use XSD to perform data validation. But now I just couldn't figure out a pattern for a string. The string format is like: XYZ. X consists of digits, its length must be 10-16, and is required. YZ (must be together) is optional, Y is fixed string like MAT, but Z is various. Z must be number between 0 and 23.
Thanks very much for your help.
Y.Ping
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The regex might look something like this:

(I haven't tested it so it might not even compile...)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
Thanks for your quick reply.
Yes, the reg exp you provided works fine when the parenthesis removed from 1([0-9]) and 2...
I find another one to work for this case
\d{10,16}(MAT([0-9]|1[0-9]|2[0-3]))?
Thanks again
 
GeeCON Prague 2014
 
subject: Question: Pattern for string in XSD