I have a column name that represents a person’s name in the following format:
firstname [middlename] lastname [, Sr.|Jr.]
For, example:
John Smith
John J. Smith
John J. Smith, Sr.
How can I order items by lastname?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A correct and faster version could look like this:
Or:
Or even:
Explain
[^[:space:]]+.. first (and longest) string consisting of one or more non-whitespace characters.(,|$).. terminated by a comma or the end of the string.The last two examples use escape-string syntax and the class-shorthand
\sinstead of the long form[[:space:]](which loses the outer level of brackets when inside a character class).We don’t actually have to use non-capturing parenthesis
(?:)after the part we want to extract, because (quoting the manual):Test