Because without the space, you are capturing EVERYTHING (.*) INCLUDING spaces, up until the very last non-whitespace character in the string. Without the space, the regex doesn't know to stop at a space.
I always use \s+ in place of literal spaces. I find it makes the regex far easier to understand, and way less likely I'll overlook a literal space (which is exceptionally easy to do).
-stevieb
In reply to Re^3: need help with explaining the output
by stevieb
in thread need help with explaining the output
by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |