3

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])
Gábor Bakos
  • 8,091
  • 51
  • 31
  • 48
  • Do a global search `/.*?[A-Z]{2}[0-9]{4}.*/g` – Rahul Sharma Mar 15 '19 at 13:45
  • Now there aren't any matches with that – Rachel Katz Mar 15 '19 at 13:48
  • 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 string – Rahul Sharma Mar 15 '19 at 13:50
  • It would be something like text, linebreak, textAB1234text. I am getting stuck on matching with a linebreak – Rachel Katz Mar 15 '19 at 14:12
  • Not sure which regex are you using. See this example: https://regex101.com/r/eb5C5q/1 and try running your regex here. – Rahul Sharma Mar 15 '19 at 14:20
  • 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? – Rachel Katz Mar 15 '19 at 14:24

1 Answers1

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

Gábor Bakos
  • 8,091
  • 51
  • 31
  • 48
  • 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? – Rachel Katz Mar 18 '19 at 15:50
  • Hi @RachelKatz added `DOTALL` (`(?s)`) too. I did not know you wanted to remove the whole content around it. – Gábor Bakos Mar 18 '19 at 20:15