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 how I can find these 3 groups?

I have a string with three different texts inside the exact line, separated by a _

I want a regex to extract the first part of the data, a regex for the second, and one for the last part.

The string is like xxxxxx_yyyyyyy_zzzzzz (where x, y, and z it’s random data).

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

I have tried this:

^[^_]*

But I can only figure out how to match the first part of the data for x.

>Solution :

You haven’t given us what programming language you are using regex from. But, generally, this is what you want:

^([^_]+)_([^_]+)_([^_]+)$

The parenthesis are "capturing groups" which can then be referred to as \x, $x, some other way where x is 1, 2 or 3. That depends on your regex implementation and programming language. Using your example string, \2 would be yyyyyyy.

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