Given the string below
[NeMo (PROD)] 10.10.100.100 (EFA-B-3) [Brocade FC-Switch ] Sensor: Power Supply #1 (SNMP Custom Table) Down (No Such Name (SNMP error # 2))
I try to get multiple matches to extract the following values:
var system = "PROD";
var ip = "10.10.100.100";
var location = "EFA-B-3";
var device = "Brocade FC-Switch";
var sensor = "Sensor: Power Supply #1";
var sensorArt = "SNMP Custom Table";
var sensorState = "Down";
var errorMsg = "No Such Name (SNMP error # 2)";
Since I am a beginner with regex I tried to define some "rules":
- Extract first value within the first round brackets e.g PROD
- Extract the value between the first closing square bracket and second opening round bracket e.g. 10.10.100.100
- Extract the value within the second round brackets e.g EFA-B-3
- Extract the value within the second square brackets e.g. Brocade FC-Switch
- Extract the value between the second closing square bracket and the third opening round bracket e.g. Sensor: Power Supply #1
- Extract the value given within the third round brackets e.g. SNMP Custom Table
- Extract the value between the third closing round bracket and the fourth opening round bracket e.g. Down
- Extract the value within the fourth round brackets e.g. No Such Name (SNMP error # 2)
Using the webpage https://scriptular.com/ I tried to achieve my goal. So far I managed to build the regex
(?=(([^)]+)))
which gives me my first match (rule 1). Somehow I fail to declare the regex to look between the brackets. What am I missing?
let [_, system, ip, location, device, sensor, sensorArt, sensorState, errorMsg] = s.match(/\(([^()]+)\)]\s*(.*?)\s*\(([^()]*)\)\s*\[([^\][]*)]\s*(.*?)\s*\(([^()]+)\)\s*(.*?)\s*\((.*)\)/)?