\s*\p{Alnum}[\p{Alnum}\s]*
Your regex, [A-Za-z0-9]+[ \t\r\n]*
, requires the string to start with a letter or digit (or, more accurately, it doesn't start matching until it sees one). Adding \s*
allows the match to start with whitespace, but you still won't match any alphanumerics after the first whitespace character that follows an alphanumeric (for example, it won't match the xyz
in abc xyz
. Changing the trailing \s*
to [\p{Alnum}\s]*
fixes that problem.
On a side note, \p{Alnum}
is exactly equivalent to [A-Za-z0-9]
in Java, which is not the case in all regex flavors. I used \p{Alnum}
, not just because it's shorter, but because it gives more protection from typos like [A-z]
(which is syntactically valid, but almost certainly not what the author really meant).
EDIT: Performance should be considered, too. I originally included a +
after the first \p{Alnum}
, but I realized that wasn't a good idea. If this were part of a longer regex, and the regex didn't match right away, it could end up wasting a lot of time trying to match the same groups of characters with \p{Alnum}+
or [\p{Alnum}\s]*
. The leading \s*
is okay, though, because \s
doesn't match any of the characters that \p{Alnum}
matches.