Regex to check if subject format was followed

Hi Everyone,
I need a regex to check if a string followed this format: Client: [LastName, FirstName]_Doc
Basically the LastName, FirstName varies. I want to check if this format was followed while ignoring case.

Client: Doe,John_Doc //true
client: Doe, john_doc //true
CLIENT: Doe, john //false

Thanks in advance :slight_smile:

Hey @mnlatam

Welcome back to the forums.

Does this Regex Pattern work for you? Was it just the pattern you needed?
(?<=client: )([\w-]+),\s*([\w-]+)_doc



1 Like

Thanks mate, @Steven_McKeering :). This pattern works :smiley:
Im just thinking of other scenarios and just wondering how can I add it to your pattern.

Let’s say
Client:Doe,John_doc //true
client:doe,john _Doc //true

Basically it’s possible that there’s no space between client: and last name and there could be a space between firstname and underscore.


Hey again

Try this pattern :slight_smile:


I have added two more β€œ\s*” which will looks for either 0 or many spaces essentially.

Thanks for the Sample, expected Output and pattern. More info on the pattern is better.

Check out my Regex Megapost also

1 Like

This also works for me. :smiley:
Will definitely check out your post. Looks detailed and comprehensive.
Thanks again mate.


1 Like

Hi bro @Steven_McKeering

Sorry forgot to mention that it’s possible that Last Name and First Name could be double names and could be short names, please see sample below:

Client:Dow Jones,Billy ray_doc //True
client: Dow Jones, B.R. _DOC //True

Appreciate your help as always. Thanks! :smiley:

Hey @mnlatam

I got your back (why I already added the β€œ-”). Names are tricky.

Try this updated pattern:

I have a second option but I am not sure if this suits your needs but this is a simplified version where First and Last name are not captured separately.


Extra unknown characters can be inserted into the square brackets β€œ[ ]”. I would use a β€œ\” to escape them just incase.

1 Like

Thanks @Steven_McKeering. Both version works perfectly. Thanks for the tip :smiley:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.