0

i am using below regex to extract information from a access-list

^\s*[0-9][0-9]\s*(?P(\S+))\s*(?P(\S+))\s*(?P\b(\S+)/(\S+)\b)\s*(?P(\S+))(?: (eq\s(?P(\S+)))?)

This is working as long as data format is

    60 permit tcp 10.33.4.0/22 10.16.129.45 eq https
    70 permit tcp 10.33.16.0/24  10.16.129.45 eq https
    80 permit tcp 10.33.101.0/24  10.16.129.45 eq https

but if i use the same regex to below data it doesn't work.

    20 permit icmp 10.33.4.0/22  10.16.129.45
    30 permit icmp 10.33.16.0/24 10.16.129.45
    40 permit icmp 10.33.101.0/24 10.16.129.45

Is it possible to use the same regex for both.

https://regex101.com/r/YtZWWc/1

1 Answers1

0

it looks like the following regex works:

^\s*[0-9][0-9]\s*(?P<action>(\S+))\s*(?P<protocol>(\S+))\s*(?P<source>\b(\S+)/(\S+)\b)\s*(?P<dest>(\S+))(?: (eq\s(?P<port>(\S+))))?
Anatoliy Sakhno
  • 146
  • 1
  • 7