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

Last match with negative lookbehind

I want to extract the content after the :, but there can be only one :.

Examples:

foo:bar             # match, extract 'bar'
foo:123             # match, extract '123'

foo:bar:123         # do not match

So that last example should not match because it has multiple :.

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 tried a negative lookbehind ^.+(?<!:):(.+)$ but that nonetheless matches and extracts from that last example.

Here’s a demo.

>Solution :

Try (regex101):

^[^:]+:([^:]+)$

This will match only lines with one : and get the string after the :

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