I am having trouble getting this regex to work and none of the canned ones I have found work reliably.
The desired result:
Produce the following via regex matches:
"Person One"
"Person Two"
"Person Three"
Out of these example lines:
By Person One, Person Two and Person Three
By Person One, Person Two
By Person One
By Person Two and Person Three
Here is what I have and note, if you break off the sections, I get partial matches but something with the lookbehind is throwing it off. Also, if there is a better way simpler but still reliable to pull all the "Persons" regardless of whether one, two, or three with an "and" is provided. It does not have to support more than the three but I would think as long as the "and" trails last the # of "Persons" can certainly remain variable without impacting the regex.
Saved current attempt (matches one but if you split my and lookbehind and run it then it does match all the "and" lines:
(?<=by )((\w+) (\w+))(?:,\s*)?((\w+) (\w+))?(?:\s*(?<=and ))((\w+) (\w+))
and
lookbehind optional – Barrett\w+
? Do you need to capture the first name and last name separately? – Barrett