Regex Parsing different types of lines

Hi, I am trying to parse a BGPO route table export

   Network          Next Hop          Metric LocPrf Weight Path
*                          0 1225 1239 701 80 ?
*                                  0 2914 1280 701 80 ?
*                                 0 1849 702 701 80 ?
*                  1             0 234 1225 1239 701 80 ?
*                                0 5459 5413 701 80 ?
*                  4             0 1239 701 80 ?
*                                   0 3561 701 80 ?

BGP Full Route Parse Only.knwf (58.5 KB)

the file is in data folder within the workflow, it has 82 lines and at least 4-5 types of lines. what is the best practice, I am trying to find the perfect regex for the whole thing but my regex knowledge is all about what I have done so far.

the full route has also a weird format, with fixed lengths, number of spaces change according to the previous fields length though.

anyways, your recommendations are appreciated

PS : the regex I came up with in 2 hours is as follows


Hi @hakandurgut,

I could get to a good point by doing a little manipulation. Just after the Line Reader node I used a String Manipulation with this expression:

regexReplace(substr($lines$,3), "\\s{2,20}", "_")

Then a Cell Splitter with underscore “_” as delimiter. Which gives you this:

From here, It should be easy to get everything as desired.


Hi @hakandurgut , I know you mentioned that the “fixed length” appear to have variations, but with the example data I found the Cell Splitter by Position was also able to produce what appears to be a reasonable result:

I used split positions of:
and column names of:
Ind,Network,Next Hop,Metric,LocPrf,Weight,Path

At the end I used String Cleaner to trim spaces from the returned columns. In KNIME 4.7, this could be done using String Manipulation (Multi Column) instead.

BGP Full Route - split by position1.knwf (80.9 KB)


thank you so much for your replies, now I was able to parse it easier.

1 Like

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