in reply to
why is regex not matching final character?
I thought \w would gobble up the whole table name first and [^\s] would stop the gobbling at the first space.
And that's just what happens. In, e.g., 'users', the (\w*) gobbles (and captures) 'user', and the [^\s] gobbles (and swallows) 's'. But all that's just what moritz just said.
Another way of looking at the regex (or any pre-Perl 5.7 regex) is with YAPE::Regex::Explain.
>perl -wMstrict -le
"use YAPE::Regex::Explain;
;;
my $rx = qr/^update\ (\w*)[^\s]/;
print YAPE::Regex::Explain->new($rx)->explain;
"
The regular expression:
(?-imsx:^update\ (\w*)[^\s])
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
update 'update'
----------------------------------------------------------------------
\ ' '
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\w* word characters (a-z, A-Z, 0-9, _) (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
[^\s] any character except: whitespace (\n, \r,
\t, \f, and " ")
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------