Regex? Argh!

Hi! I’m trying to do something incredibly simple and I’m going nuts. I’m a complete programming newbie, and this is far too big for Excel.

Basically, I have a load of big CSV files, where the data looks as follows:

  • 30.25

  • 30.25-

For any negative value, I want to move the “-” to the front of the string so that I can convert it to an integer.

I’m going nuts trying to do this with regex formulas: regexreplace($Net$,((?:\d+.)?\d+)-),-$1)

But having very little luck. Any help would be super appreciated!

The following pattern works in KNIME
Pattern: ((?:\d+.)?\d+)(\-?)
Replace: $2$1
image

2 Likes

Thank you so much! This absolutely works for individual cases, now I’m just missing some syntax that I’m not getting right.

I’m trying to apply this to a full column, doing the following:
regexReplace($Net$, ((?:\d+.)?\d+)(-?) ,$2$1)

I think having the $ around the 2 is somehow confusing it as I’ve already referenced $Net$, and I’m getting the following error: “Invalid settings: No such column: 2 (at line 1)”.

Thanks again!

Hi @Spoon,

now i realize which Node you were using ;-). You need to use double backslashes as an escape sequence and quotation marks:


This worked for me. Hope it will work for you too

3 Likes

You’re absolutely wonderful. Can’t thank you enough- wish I could send some wine your way :slight_smile:

1 Like

Me too. I also wish you could do that! :smile:

2 Likes

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