Your initial pattern:
"^(%w+)%s+(%w+)%s+\'(%w)\'@\'(%w)\'$"
- The last two captures in your pattern lack + specifiers to indicate that they are to read 1 or more characters.
- _ is not a word character matched by
%w
. You will need a character class including _ everywhere you would need to match it. - The escaping of ' within a "-quoted string is unnecessary.
With some improvement:
"^(%w+)%s+(%w+)%s+'([%w_]+)'@'([%w_]+)'$"
Alternatively: If you wanted to match anything within a set of quotes '
, you could match against its inverse class:
"^(%w+)%s+(%w+)%s+'([^']*)'@'([^']*)'$"
([^']*)
will capture anything (including nothing) that isn't '
, until the end of the string or a '
is found.