I need to parse some text, which consists of a six digit code, an optional confirmation string (one of 'ok', 'yes' or 'no'), followed by some free text. So it might look like:
123456 Ok Mary had a little lamb
... but might equally be
123456 Mary had a little lamb
...and I'd need each of those three parts captured separately.
I've got this regex:
/^\s*?(\d\d\d\s?\d\d\d)\s*?(yes|no|ok)?\s*?(.*?)$/i
...which doesn't work! I can tweak it so that it works if you always have the 'yes', 'no' or 'ok', but that is an optional element.
Any thoughts very much appreciated.