in reply to need help with explaining the output

Read the Perl perlretut, especially the part on character classes. You probably want a common class like \w.

Your first regexp matches everything up until the second one matches.

It's a good use of your time to stop what you are doing, take 30 minutes, and read and understand the tutorial !

Update: links to docs

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: need help with explaining the output
by perlynewby (Scribe) on Jul 16, 2015 at 00:26 UTC

    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

      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.