0

I got info about ports from cisco switchs. I get the information with a command on the switch.

Show interfac status

And I got lines like:

GI1/0/1      1089.22 Office_Name      disabled      88      1000     Full

Or:

FA0/1        Big Room                 connected     120     100      Half

And Im trying to analyze the data with regular expression. The end result should be:

Line[0] = GI1/0/1
Line[1] = 1089.22 Office_Name
Line[2] = disabled
Line[3] = 88
Line[4] = 1000
Line[5] = Full

What is the best way to make it?

(I tried this expression but its work very bed)

/\D+\d+((/\d)+(\.\d+)?)?\s(.*)\s(disabled|connected)\s(.*)\s(10|100|1000)?\s(Full|Half)/
Razdom
  • 137
  • 12
  • StackOverflow expects you to [try to solve your own problem first](http://meta.stackoverflow.com/questions/261592), and we also [don't answer homework questions](https://softwareengineering.meta.stackexchange.com/questions/6166) (ignore if you're not asking about hw). Please update your question to show what you have already tried in a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). For further information, please see [how to ask good questions](http://stackoverflow.com/help/how-to-ask), and take the [tour of the site](http://stackoverflow.com/tour) :) – giorgiga Feb 06 '18 at 18:00
  • @giorgiga I added the expression I made that does not work – Razdom Feb 06 '18 at 18:03

1 Answers1

1

You might use split:

let log = [
'GI1/0/1      1089.22 Office_Name      disabled      88      1000     Full',
'FA0/1        Big Room                 connected     120     100      Half'
]

let chunks = log.map(e => e.split(/\s{2,}/))

console.log(chunks)

If your lines are tab-separated use split(/\t+/)

Kosh
  • 16,966
  • 2
  • 19
  • 34