Given the statement
the cat and the dog played together
I can grab both cat and dog with this regex
(cat).*(dog)
There will not always be a cat in the sentence, so I make the first capture group optional
(cat)?.*(dog)
When using an optional capture group, it .*always captures the entire first part, ignoring the optional capture, even if there is one. How can you grab a cat if it is, but if it is absent, the regular expression will still match the dog?
I tried to make the star inanimate
(cat)?.*?(dog)
and tried to use |instead of an optional capture group, but the first capture group is always ignored.
Example result, http://regex101.com/r/pR1kZ9