Regex String replacer node - need help


#1

Hi All,

i have an issue using regex String replacer node.

I have the following strings, sometimes with blank (missing value), or - 0 :
214242873

214149086
214173229
“- 0”
214184341

I can match (- 0) but can i match missing values (blank cells)

or how can i exclude anything different from my id struture : (\d{0,9})

thanks
david


#2

Your structure would cover every digit (0-9) with any length between zero and 9. Maybe you would want to check if the structure is an uninterrupted sequence of exactly 9 digits.
([0-9]{9})
or
^([0-9]{9})$

^marks the start of a string and $ the end.


#3

Hi mlauber71,

Many thanks for your feedback.
It works perfectly for my IDs : 214184341, but i would like to match anything different

I tried lookalike, ^(?!([0-9]{9}))$ but do not works, and i think String replacer do not work for missing values

thanks
david


#4

Hi @davidd,

You can use ([^0-9].+) expression for the String Replacer node, but you’re correct, you will still have to handle missing values.

I’d suggest using either the Column Expression node with the following expression:

if (length(column(“column1”)) < 9){
“replaceString”;
} else {
column(“column1”);
}

or to do the same with the String Manipulation node to output the length and the Rule Engine to check it:

$length$ < 9 OR MISSING $column1$ => “replaceString”
TRUE => $column1$

Please find attached a sample workflow.

RegexStringReplacer.knar.knwf (6.2 KB)

Best,
Anna


#5

Hi Anna,

Many thanks for your help.
Works perfectly. extremly helpfull

Best,
David