I am trying to match regex
.*(bob|alice).*
against bob and alice like to text each other
I expected 2 matches, but only "alice" is matched.
When removing the wildcards, then bob and alice are matched.
(bob|alice).
Question: why adding .* changes the behaviour? I thought it means zero or any characters?
>Solution :
The behavior you are seeing is expected, given that the leading .* in your pattern is greedy, and therefore will match all content up to the last bob or alice. Most likely, you can get away with:
\b(?:bob|alice)\b

