I need assistance validating a specific element in an XML document using regular expressions.
<ConfigOption>value</ConfigOption>
Here are the requirements for ConfigOption:
- Allowed characters include letters, numbers, underscores, and spaces.
- The format CONFIG-XX is acceptable, where XX represents numbers.
- The format CONFIGNAME?config=XX is also permitted, with XX being numbers.
This is the regular expression I have so far:
(^[a-zA-Z0-9 _]*$)|(?:\??config=\d)|(^CONFIG\-\d$)
For example:
- 'hello' should pass validation.
- 'hello?config=20' should pass validation.
- 'CONFIG-20' should pass validation.
- 'hello-' should fail validation.
- 'hello*' should fail validation.
Can someone help me correct my regular expression? Even after testing 'hello=' or 'hello*' on 'https://regex101.com/', it still matches.