Column Rename Regex

Hello everyone!

In an excel file I have a column that is renamed “Portofoliul initial-retrasi (#90)”. On the next run of the flow, this column will be called “Portofoliul initial-retrasi (#91)”. As a rule, every time the flow is run, this column will have +1 added to the digits in the column name. I want to rename this column with “Portofoliul initial-retrasi”, but I can’t. I tried the Column Rename(Regex) node with the following configuration: searchstring: "(?i)Portofoliul\sinitial-retrasi\s(#\d+) " ; replacement: “Portofoliul initial-retrasi” but it does not work.
Is there another option?

Have a nice day!

Hello @madac

The issue with your current code in ‘Column Rename (Regex)’ node; it 's that you can’t negate the replacement grouping…

The right approach is to negate the unwanted string from the replacement text grouping $1, this is:

(?:\s\(#\d+\))(.*)

Alternatively you can exclude the unwanted from the replacement grouping:

(Portofoliul initial-retrasi).+

BR

3 Likes

@madac Will this workflow achieve your goal without using Regex?

1 Like

Hi @madac,

You may want to know that when writing regex here on the forum, it is best to mark the regex as “pre-formatted” text, by highlighting it and clicking the pre-formatted text button on the forum toolbar

image

If you don’t, we cannot easily see what your actual regex was, because some characters get interpreted by the forum software.

So whereas your regex code might have been this:
(?i)Portofoliul\s*initial-retrasi\s*\(#\d+\)
without it being marked as pre-formatted, we only see it as this, and some of the \ and * (and potentially other characters) get lost:
(?i)Portofoliul\sinitial-retrasi\s (#\d+)

The regex that @gonhaddock supplied (or a combination of both depending on how specific it needs to be), replacing with $1 should resolve your problem.

3 Likes