I have a simple problem, but I can not solve it. Or, my string is in the format ID: dddd with the following regular expression:
/^ID: ([a-z0-9]*)$/
or as follows: ID: 1234 Status: 232 , therefore with the following regular expression:
/^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
Now I want to make one regex that can handle both. The first thing I came up with was the following:
/^ID: ([a-z0-9]*)$|^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
It matches, but I looked at conditional regular expressions and thought that something should be possible line by line (pseudo-codish)
if the string contains /Status:/ /^ID: ([a-z0-9]*)$/ else /^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
I canโt get it right. I thought I should use /?=/ , But I have no idea. Sort of
/((?=Status)^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$|^ID: ([a-z0-9]*)$/
but it does not work.
You can help?
source share