regex

why this does match, too?


this is the target string:

Marius Müller Osterhase

this does match:

Marius .+Osterhase

why does this match, too?:

Marius .+ Osterhase

I thought '+' is very hungry, '.' eating everything and spaces, but no newline. So i thought this should be the target to match: Marius Müller Osterhase (2 spaces between Müller and Osterhase)


Solution

  • It WILL try to match the rest of the string. That fails, so it backtracks until it either matches or can't anymore. In this case, it finally matches "Müller".