65638

Question:
I have 10 "bracketed" variables ("[EVENT]", "[PROTOCOL]", "[SESSION]", etc...) I need to restrict an attribute. Valid cases are:
<ol><li>Any string without brackets </li> <li>Mentioned 10 "bracketed" variables</li> <li>Any bracketed variable(s) concatenated with regular strings, for example: My[EVENT]<em>for</em>[PROTOCOL]@google.com</li> <li>Empty string</li> </ol>Non-valid cases:
<ol><li>Any string inside brackets, except 10 predefined</li> <li>The same with concatenations </li> <li>Strings with only opening or closing bracket </li> </ol>To be short - inside brackets only predefined variables are allowed and they can be concatenated with any string.
Thanks in advance
Answer1:Read the regular expression as follows: <strong><em>The concatenation of one or more substrings containing no brackets except for those surrounding EVENT, PROTOCOL, or SESSION.</em></strong> This is trivially extended to additional acceptable bracketed variables.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:attribute name="attr">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^\[\]]*"/>
<xs:pattern value="([^\[\]]*\[(EVENT|PROTOCOL|SESSION)\][^\[\]]*)+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>