Your regex uses .*. Expressed in language other than the technically correct form what you'll find (and you should) in perldoc perlretut and friends: that's a 'greedy' form -- it matches anything, any number of times, until it gets to the LAST data which would match the NEXT element in the regex. The addition of the ? changes the rule -- in this case, to match anything any number of times but AS FEW AS POSSIBLE before any instance of the NEXT element in the regex.
Hope this helps.
In reply to Re: Regex non-greedy match
by ww
in thread Regex non-greedy match
by Jessarah FL
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |