I have a simple problem, yet i am unable to solve this.
Either my string has a format ID: dddd
, with the following regular expression:
/^ID: ([a-z0-9]*)$/
or as follows: ID: 1234 Status: 232
, so with the following regular expression:
/^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
Now i want to make one regular expression that can handle both. The first thing i came up with was this:
/^ID: ([a-z0-9]*)$|^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
It matches, but i was looking into conditional regular expressions, and was thinking that something should be possible along the lines of (pseudo-codish)
if the string contains /Status:/
/^ID: ([a-z0-9]*)$/
else
/^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$/
only, i can't get this expressed correctly. I thought i should be using /?=/
but have no clue how.
Something like
/((?=Status)^ID: ([a-z0-9]*) Status: ([a-z0-9]*)$|^ID: ([a-z0-9]*)$/
but that doesn't work.
Can you help?