vb.net Need regex to find suffix in name

Could someone show me how to use regular expression to look for common suffixes in a person's name?

rutledgjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Do you mean like "Ph.D.", "Jr.", "Sr.", etc.? If so, here is a start:

Dim pattern As String = "ph\.d\.|jr\.|sr\.|Atty"

Open in new window


You can add more suffixes by inserting a pipe ( | ) and then the suffix. Make sure you escape any dots with a backslash like I did above.
0
rutledgjAuthor Commented:
Fine, Then how do you call the expression to return a true/false condition?
0
käµfm³d 👽Commented:
Be sure to turn on case-insensitivity. I forgot to demonstrate that above.

Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase)

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

käµfm³d 👽Commented:
You can use the method I demonstrated immediately above for a true/false return.
0
rutledgjAuthor Commented:
Is it possible to use the expression to just remove it from the name to begin with?

MyName.Replace(pattern,"")?

0
käµfm³d 👽Commented:
Certainly:

Regex.Replace(input, pattern, String.Empty, RegexOptions.IgnoreCase)

Open in new window

0
käµfm³d 👽Commented:
Also, be careful with which suffixes you add to your pattern. I demonstrated "Atty" (short for attorney) in the pattern above, but what happens if the name you are inspecting is "Patty". You will effectively change the person's name to "P". You can try adding word boundaries around the pattern to help mitigate this:

Dim pattern As String = "\b(?:ph\.d\.|jr\.|sr\.|Atty)\b"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rutledgjAuthor Commented:
Ok. Thanks. Big help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.