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 a pattern with digits, letters AND hyphens

This is the example:

foo /sup/ssddssd/433443/fg54g4fg5-e653-4c13-81f3-bvbt4456gfdb4-43df
foo /eaa/asder-zxc2-bg34s-23xc-34sdf23ds2c-43dfgfd/fgfsdga/2432322

How can I only regex the fg54g4fg5-e653-4c13-81f3-bvbt4456gfdb4-43df pattern? The pattern isn’t always, as it shows, at the end of the strings.
I’ve tried [\w-]+ but it includes the entire string

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 :

To match two or more segments of word characters separated by hyphen, use

\w+(?:-\w+)+

See this demo at regex101

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