I am trying to match a string that might be either:
NAME: JOHN DOE DATE: 01/01/01
or
NAME: JOHN DOE
I think I understand optional groups, but of course if I make DATE: and the date group at the end optional, the (.*) group that captures JOHN DOE will capture everything to the end of the string.
From reading a bit, it seems I want a “negative lookahead”, so that my (.*) group only matches up to the position when DATE: appears. I tried:
(NAME: )(.*(?! DATE:))( DATE: )?(.*)?
But regex101.com still matches everything in the string after NAME: as group 2. How do I match the name string up until DATE: and have optional groups for the date label and value?
I’m going to put this in Java, if that makes a difference.