Replace specific instances of character but not all

Hi all-
I’d like to remove only specific instances of a character but not all. I have a column of numbers that sometimes has “>” character in front of number. I’d like to remove the “>” character for all instances, EXCEPT when followed by the number 1. For example if the value is “> 0.8” I’d like it to be “0.8”, but if the value is “> 1.0” or “> 10.0” I’d like to leave the “>” symbol in. Using String Manipulation node and the expression regexReplace($col1$,"> [^1]" ,"") gets me close, in that the “> 1.0” remains, but I also seem to loose the 0 for “> 0.8”. Any help with regex syntax would be appreciated. Thanks!

Hi @lgarrenton,

i think what you are looking for is a regex with “negative look ahead”
So in your case
“> (?!1)”

and then replace by empty.
Basically find a "> " which is not followed by an 1 but do not include the “not 1” in the match

Your regex currently is
“> [^1]”

the difference in a look behind to your regex is that the look behind part (?!1) is not included in the matching… so if you replace the match with empty the “not 1” stays while only the "> " will be removed

Here a visual example for the look ahead:

3 Likes

Thanks so much! This worked for me.
-L

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.