I am trying to match name patters. A name can either be
lastname,firstname middleinitial
or
lastname,firstname
i am trying to create a regex to check the last 2 chars of a string are [space][anychar]
I found a tutorial online which says to match A to the end of the string you do
A$
"A" at the end of a line
In applying this to mine i was trying to do something like this, and a number of forms of this too. I literally have no idea though :/
([\\s][A-Za-z]$)
You can easily check the last two characters without a regular expression.
This is both clearer (more readable) and also executes faster than a regular expression. And it keeps you from having to worry about non-English letters (
A-Zis a very limited set!).(P.S. You could also use
char.IsWhiteSpaceinstead of directly comparing to' '; then it would work with other space characters too. For example, Asian users are likely to enter a U+3000 ideographic space instead of the standard U+0020 space.)