Regex for extracting strings

Hi everyone,

I want to extract the “PLTR” and “CVTR” text from all rows in column VORGANGBEZ shown in the image attached below.

Could someone please tell me what node(s) I could use and what regular expression -if necessary- I should use.

Thanks in advance.

1 Like

Hi @SantiN

Why are some instances of PLTR and CVTR highlighted but not others?

What does your desired output look like?

2 Likes

My thought is instead of using Regex function, you can simply use a JAVA snippet to write an if-else statement says if the column contains ‘PLTR’ then ‘PLTR’ elseif column contains ‘CVTR’ then CVTR.

1 Like

You can use String Manipulation Node with regexReplace
If your strings are only PLTR and CVTR you can use a regular expression like this:
regexReplace(yourColumn, “(PLTR|CVTR)”, “$1”)

If you want match any uppercase string with exactly 4 chars, regex becomes

regexReplace(yourColumn,"([A-Z]{4})","$1")

1 Like

Errata corrige:
correct regex expressioons are:

regexReplace(yourColumn, “.*(PLTR|CVTR).*”, “$1”)
regexReplace(yourColumn,“.*([A-Z]{4}).*”,“$1”)

1 Like

If you’d rather not use RegEx, this should also be possible with a Rule-based Row Filter node, using an expression similar to

$VORGANGBEZ$ LIKE "*PLTR*" => TRUE
$VORGANGBEZ$ LIKE "*CVTR*" => TRUE

2 Likes

Hi @elsamuel,

I highlighted only some of them as an example of what I wanted to be extracted.
I want all of them (PLTR and CVTR) extracted in a new column.

Hi eric020977,

Sadly, I know nothing about Java coding.
Could you please give me an example of what code you would write to get that “PLTR” and “CVTR” are extracted from VORGANGBEZ column to a new column?

Hello pigreco,

I tried the first regex expression and got an error message, however, I used the regex in a split node and it worked quite good.


image

Thanks!

1 Like

Correct image of regex split node…

1 Like

Hello ScottF,

I used the Rule-based Row Filter, but I didn’t want to filter any row as there are some rows which have neither “PLTR” nor “CVTR”. However, I used instead the Rule Engine node as shown below and it worked very well.

Thanks for the hint about using the wildcard (*)!

4 Likes

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