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

in the end, my solution was to use \w to get the regex to properly capture on the string for first name and last names...but

I did read the tutorials on regex and still unable to understand it how the space there worked

thanks

  • Comment on Re^2: need help with explaining the output

Replies are listed 'Best First'.
Re^3: need help with explaining the output
by stevieb (Canon) on Jul 16, 2015 at 00:36 UTC

    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

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

      UPDATE: Which is the default in Perl 6.