I've been having trouble understanding how to make this regex more dynamic. I specifically want to pull out these for elements, but sometimes part of them will be missing. In my case here, it doesn't recognize the pattern because the 4th group isn't present.
For example, given the 2 strings:
Rafael C. is eating a Burger by McDonalds at Beach
David K. is eating a Burger by McDonalds
John G. is eating a by at House
I'm trying to pull out the [name], [item], [by name], [at name]. It will always be in this patterns, but parts of it may be missing at times. Sometimes it's the name missing, sometimes it's the item, sometimes its the name and by name, etc. So I'm using:
(.*) is eating a (.*) by (.*) at (.*)
But because it's missing in the second string, it doesn't recognize it. I've tried using lookbehind/lookaheads. I've tried using quintifiers, but having a hard time understanding what it is to get exactly those 4 groups, as you can see below:
Output desired:
I'd like it capture:
[Rafael C., Burger, McDonalds, Beach]
[David K., Burger, McDonalds, '']
[John G., '', '', 'House']
