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

Time:06-19

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 _.

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 ,:

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

CodePudding user response:

If lookahead is supported and you don't need to check for the opening { try e.g.

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

See this demo at regex101

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

  • Related