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 only match parts of a string where words not ending with

Here is my string

 something_a12345678901234567890123 something_else_a12345678901234567890123 hello my_dude

I’d like to catch only

 hello my_dude

In short, every bit (where a bit is separated by space) not ending with

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

 _[a-z0-9]{24}

Here is my regex

 /[a-zA-Z0-9\\-_]+(?<!_[a-z0-9]{24})/g

But it’s catching almost everything…

>Solution :

Add word boundaries:

\b[\w-]+(?<!_[a-z0-9]{24})\b

See live demo.

Note simplification of regex too.

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