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

In a string that is between 2 characters, find text after last delimiter

I need to find all _ in a string, but only if the whole string is between { and }. Also, the string we need to check must come after the last delimiter: ,.

An example (sorry for the "messy" example):

{some_text_1,some_text_1_more,some_text_1_more_more,0_1_2}INTERSECT{some_text_2,some_text_2_more,some_text_2_more_more,text,abc_efg_hijk}

The strings I need to go over are:
0_1_2 and abc_efg_hijk. I need to catch their _.

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

The reason for this is that I want to replace _ with a different delimiter as this one is causing issue. I will use regexp_replace after finding the correct regex.

For now I only managed to capture the strings between { and } using the following regex, but I failed to get _ after the last iteration of ,:

(?<=\{)(.*?)(?=\})

>Solution :

If lookahead is supported and you don’t need to check for the opening { try eg

_(?=[^,{]*})

See this demo at regex101

It looks if there is a closing } ahead with any amount of [^,{] in between.

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