RegEx and corresponding codes from right to left
Digressing a bit with RegEx, I have 4 codes per line
code4: CODE3: Codex2: code1
every code is optional except CODE1
So I could have ab: bc: de: fg
or
Bc :: fg
of
ab: fg
In every case of the above CODE1 = fg dnd for my dear life, I cannot develop a Regex
It would be easy to do as standard parsing, but no coincidence because of the objects buisness needs to be done via regex :-( and back via vb.net Regex.matche, groups ("Code1") fg (I hope that makes sense)
Thanks in advance for your help
Ending out a RegEx bit that does the job, bit a mess 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
source to share
There is no need to use a regular expression here.
I don't know what language you are using, but split the string by ':' and you have an array of codes.
If you really want to check if the string is correct for this then
/(\w*:){0,3}\w+/
matches your description and several examples you have given.
source to share