I'm trying to match multiple log entries per line. Every entry is in proceeding format:
instance Role id [state] [flags] [activity] [status]
-------------------------------------------------------------------------
30:9876543210 Secondary 1122334455 V InTransition
10:0123456789 Primary 9874563210 IB EV FDown
Items between square brackets are optional, while others are mandatory, and they are space separated.
Regex that I wrote, doesn't work as intended, there is a particular case, that I discovered so far, where match fails.
Current regex: (?<instance>\d+:\d+) (?<role>[a-zA-Z]+) (?<id>\d+)\s?(?<state>SB|IB|RD|DD)?\s?(?<flags>[A-Z]+)?\s(?<activity>InTransition|Down|Up)?\s?(?<other>[a-zA-Z]+)?
Entry that fails: 30:9876543210 Secondary 1122334455 IB InTransition
| Result | Expected Result |
|---|---|
| instance: 30:9876543210 | instance: 30:9876543210 |
| role: Secondary | role: Secondary |
| id: 1122334455 | id: 1122334455 |
| state: IB | state: IB |
| flags: I | flags: |
| activity: | activity: InTransition |
| other: nTransition | other: |
There is probably much better solution than mine, even if you have a slightest clue how to fix regex that I wrote or you have your own, please feel free to comment. Thank you.