gcue Posted October 23, 2023 Posted October 23, 2023 (edited) i have a list of users who have titles attached to their names. i would like to strip anything after their last name. so essentially want to get first and last name only (ie: bob smith in example below). having trouble with syntax $string = "bob smith cima, phd, ma" $full_name_only = StringRegExpReplace($string, '^([[A-Za-z]+\h.[A-Za-z]+]).*$', "$1") any help is greatly appreciated! Edited October 23, 2023 by gcue
Andreik Posted October 23, 2023 Posted October 23, 2023 (edited) Something like this? Is this pattern consistent regarding format? $string = "bob smith cima, phd, ma" $full_name_only = StringRegExpReplace($string, '^([a-zA-Z]+ )(?:.*?)([a-zA-Z]+),(?:.*?)$', "$1$2", "") Edit: I am a little bit confuse about this "so essentially want to get first and last name only (ie: bob smith in example below)". First and last in this case isn't bob cima? Edited October 23, 2023 by Andreik
gcue Posted October 23, 2023 Author Posted October 23, 2023 3 minutes ago, Andreik said: Something like this? Is this pattern consistent regarding format? $string = "bob smith cima, phd, ma" $full_name_only = StringRegExpReplace($string, '^([a-zA-Z]+ )(?:.*?)([a-zA-Z]+),(?:.*?)$', "$1$2", "") Edit: I am a little bit confuse about this "so essentially want to get first and last name only (ie: bob smith in example below)". First and last in this case isn't bob cima? cima is one of Bob Smith's titles. so only looking to end up with bob smith (first 2 words and ignore everything else)
Solution Andreik Posted October 23, 2023 Solution Posted October 23, 2023 (edited) $string = "bob smith cima, phd, ma" $full_name_only = StringRegExp($string, '^([a-zA-Z]+ [a-zA-Z]+)(?:.*?)$', 3) MsgBox(0,'', $full_name_only[0]) Edited October 23, 2023 by Andreik
bladem2003 Posted October 24, 2023 Posted October 24, 2023 or this $string = "bob smith cima, phd, ma" $aStringSplit = StringSplit($string, " ") MsgBox(0,'', $aStringSplit[1] & " " & $aStringSplit[2])
mikell Posted October 25, 2023 Posted October 25, 2023 or this ;$string = "bob smith cima, phd, ma" $string = "brian o'connor cima, phd, ma" $res = StringRegExpReplace($string, '^([[:alpha:]'']+) ((?1)).*', "$2, $1") MsgBox(0,'', $res) gcue 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now