in reply to Re^2: need help with explaining the output
in thread need help with explaining the output

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

Replies are listed 'Best First'.
Re^4: need help with explaining the output
by u65 (Chaplain) on Jul 16, 2015 at 11:32 UTC

    And use of the 'x' modifier may help by ignoring literal spaces in the regex.

    UPDATE: Which is the default in Perl 6.