Stuggling a little bit with the RegEx, I’ve got 4 codes in a string
CODE4:CODE3:CODE2:CODE1
each code is optional apart from CODE1
So I could have ab:bc:de:fg
or
bc::fg
of
ab:::fg
In each case of the above CODE1 = fg dnd for the dear life of me I can’t work out the RegEX
Would be easy to do as a standard string parse, but unforunatly because of buisness objects in needs to be done via regex 🙁 and return via a vb.net RegEX.matche,groups(‘Code1’) fg (I hope that makes sense)
Thanks in advance for any help
Ended up with a bit of RegEx that does the job, bit messy but it works
(^(?<code1>[\w]*)$)|(^(?<code2>[\w]*):(?<code1>[\w]*)$)|(^(?<code3>[\w]*):(?<code2>[\w]*):(?<code1>[\w]*)$)|(^(?<code4>[\w]*):(?<code3>[\w]*):(?<code2>[\w]*):(?<code1>[\w]*)$)
Ta all
There’s no need to use a regular expression here.
I don’t know what language you’re using, but split the string on ‘:’ and you’ll have an array of codes.
If you really just want to validate whether a string is valid for this then
matches your description and the few examples you’ve given.