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 for optional parts of string

How can I match all four variants shown below with one regular expression?

ABC
ABC_DEF
ABC_DEF_GHI
ABC_DEF_GHI_JKL

ABC, DEF, GHI, JKL do not represent number of characters.

I’ve tried something like this (only for second option) but no luck: [A-Z]+(_[A-Z]?+)

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 :

here:
^([A-Za-z]+)(_[A-Za-z]+)*$

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