I am trying to limit the contents of an xml element using a regex pattern within the schema but I just cant get it working and the more I add the worse it seems to get.
The requirements are as follows:
- The element string can’t be longer that 512 characters (This bit’s easy but added for completeness)
- The string consists of multiple key value pairs.
- The key value pairs will be separated by ‘^’
- Each key value pair consists of a 3 character key, followed any number of characters for the value.
- The keys will be separated from the values by ‘|’
An example of the XML would be:
<myElement>
ABC|This is some value text for key ABC^DEF|This is some value text for key DEF^GHI|This is some value text for key GHI^JKL|This is some value text for key JKL^
</myElement>
In the question you say “The key/value pairs will be separated by ‘^'”, but the example shows the key/value pairs terminated by ‘^’, so I’m assuming that’s what you want.
The key matches
\w{3}(3 letters or digits).The value matches
[^^<]*(any number of any characters except^).The complete regex is
(\w{3}\|[^^]*\^)*.