Regex For Multiple Lines in Knime
Asked Answered
D

1

8

I am using Knime to find a pattern like AB1234 anywhere in the data of one of my columns X. X can have multiple lines in each cell but I can't figure out how to search all of the lines. Below is my current regex, can you please help me search all lines

I tried this first to search but it only matched if that pattern appeared in the first line of the cell, did not work for cells with line breaks:

.*?[A-Z]{2}[0-9]{4}.*

Then I tried to do this to search all of my lines but it didn't work and only searched the first line again:

(.*|[\r\n])[A-Z]{2}[0-9]{4}(.*|[\r\n])
Discreditable answered 15/3, 2019 at 13:35 Comment(6)
Do a global search /.*?[A-Z]{2}[0-9]{4}.*/gFeatherbrain
Now there aren't any matches with thatDiscreditable
Can you give us an example string? /g is for global search. Meaning it'll match all occurrences. You'll usually also see i which means ignore case. The "g" flag indicates that the regular expression should be tested against all possible matches in a stringFeatherbrain
It would be something like text, linebreak, textAB1234text. I am getting stuck on matching with a linebreakDiscreditable
Not sure which regex are you using. See this example: regex101.com/r/eb5C5q/1 and try running your regex here.Featherbrain
I am using the regex from the node "String Manipulation" in Knime. My data originally comes from ServiceNow and then I load it into Knime via an excel file. Certain cells in my excel files have multiple lines and I cannot match if my pattern exists outside of the first line. Does that make sense?Discreditable
P
1

You can use the inline embedded flag expression for multiline mode, (?m) and the embedded DOTALL flags, (?s) together:

Your first expression would look like this:

(?ms).*?([A-Z]{2}[0-9]{4}).*

Screenshot of the workflow

Philistine answered 15/3, 2019 at 16:17 Comment(2)
this still does not work - how does the (?m) work in Knime? Should I be specifying that expression with the rest of the regex code in the string manipulation node?Discreditable
Hi @RachelKatz added DOTALL ((?s)) too. I did not know you wanted to remove the whole content around it.Felon

© 2022 - 2024 — McMap. All rights reserved.