Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex to match string between two strings

I have a string that can be "Hello World!" or "Hello John Doe!" or "Hello user2345!".

I need to validate that said string is one of the above and not "Hello !". i.e. some character has to exist before the exclamation(!) mark.

How do I validate this with regex please?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could match on:

\bHello(?: \w+)+!

which would match Hello followed by at least one following word, ending in !.

Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading