Jump to content

trying to first and last name only


Go to solution Solved by Andreik,

Recommended Posts

Posted (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 by gcue
Posted (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 by Andreik
Posted
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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...