-2

I have a column with string values present in several lines. I would like to only have the values in the 6th line, all the lines have varying lengths, but all the cells in the column have the information I need in the 6th line.

I am honestly absolutely new and have no background in Java nor KNIME - I have scoured this forum and other internet sources, and none seem to tackle what I need in KNIME specifically - I found something similar but it doesn't work in KNIME:

Regex for nth line in a text file

1 Answers1

0

Your answer will probably need to be broken into two parts

  • How to do a regex search in KNIME
  • How to do a regex search for the 6th line

I can help with the regex search, but I don't know KNIME

To start with, you want to know how to search for a single line which is

([^\n]*\n)

This looks for

  • *: 0 or more of
    • [^\n]: anything that isn't a new line
  • followed by \n: a new line
  • and (): groups them together into a single match

We can then expand this into: ([^\n]*\n){5}([^\n]*\n){1} Which creates 2 capture groups, one with the first 5 lines, the second with the 6th line.

If KNIME supports Non-Capturing groups you can then expand that into the following so that you only have one matching capture group. You can decide for yourself which you like best.

(?:[^\n]*\n){5}([^\n]*\n){1}

I've created an example you can test on RegExr

Regardless of which way you go, make sure to document the regex with comments or stick it into a variable with a very clear name since they aren't particularly human readable

Chris Rudd
  • 709
  • 7
  • 13