Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to exclude word (XML Schema flavor)

Tags:

regex

xsd

currently I'm trying to find a regular expression with the following condition:

Match:          FOO_.* (valid if the string contains FOO_ at the beginning)
Don't Match:    FOO_BAR (not valid if the string contains BAR)

Usually I would use the following expression:

FOO_(?!BAR)

My problem with that solution is, that I want to use it in a xml schema. Using it with a parsers brings up the following error message:

schema.xsd:50: element pattern: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}pattern': The value 'FOO_(?!BAR)' of the facet 'pattern' is not a valid regular expression.
WXS schema schema.xsd failed to compile

Is there a readable ;-) working solution or is it just not possible inside a xml schema?

like image 998
echox Avatar asked Oct 08 '22 05:10

echox


1 Answers

The Lookaround part (?!BAR) of your expression is not supported in XML schema.

  • http://www.regular-expressions.info/xml.html
  • http://www.w3.org/TR/xmlschema-2/#regexs

For your specific example the following expression should give you an idea how you could workaround this limitation:

FOO_([^B].*|B([^A].*|A([^R].*)?)?)?
like image 54
splash Avatar answered Oct 12 '22 11:10

splash