Regex for Column Filter Numbers

Hi,

Don’t laugh, but I’ve literally spent 2+ hours trying to figure this out so I’m giving up and asking for help.

My prediction columns are labeled “P (Target=Buy) (#1)” and then “P (Target=Buy) (#2)” , etc (they don’t actually have the quotes). What is the regex pattern to filter by “#1” , #2, #3 etc…?

Thank you in advance.

@cybrkup,

I’m not totally sure about requirement.
If I assume that you would to filter for “P (Target=Buy) (#1)” and get this column as result.
So you may use the Column Filter Node.
According to my knowledge using something like

.*(#1)

as the regex to select the column should work.
Please do not forget to check regex selection below the regex itself.

When applying to the column filter node this works perfectly for me.

@cybrkup

I should have had a look to the regex before posting. This regex will obviously not bring the correct result, the brackets will return just a part of the input string
Apologise for this stupid Copy&Paste error.

The correct regex is

.#1.

Unfortunately I’m not able to correkt my first post.

Hello @cybrkup,

seems to me wildcard approach is sufficient here:

P *

If you really what to use regex to get column which have “#d+” (be careful as you might have columns with that pattern which are not prediction columns) use following regex:

.*#\d+\)

Br,
Ivan

Thanks all, I got it.

I should have clarified my original post in that I need to filter in a loop. i.e. Loop 1 I’m looking for columns with “1” in the name, etc. I tweaked Ivan’s answer to do this, so for loop 1 the regex is:
.*#1+)

for loop 2 it is:
.*#2+)

Thanks again for the guidance.

1 Like

Hello @cybrkup,

glad you found a way. Only exclude + from regex as it will include P (Target=Buy) (#11) in first iteration in case you have that many columns.

Br,
Ivan

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