This is because principle 0 of regex says
Principle 0: Taken as a whole, any regexp will be matched at the earliest possible position in the stringSo while your '.+?' dictates a preference for the smallest amount of characters to match, in the end this preference is overruled.
In reply to Re^2: regexp: least inclusive match?
by varian
in thread regexp: least inclusive match?
by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |