Matching ASN.1 string with python regexp

Viewed 150

How can I match this ASN.1 string with python regexp

"::= { bgpPathAttrEntry 6 }"

I try this regexp:

\s+::=\s*{\s*(?P<entry>\S+\s\d+)}\n

and fail.

1 Answers

You can use

::=\s*{\s*(?P<entry>[^{}]*?)\s*}

See the regex demo

Details

  • ::= - a literal substring
  • \s*{\s* - a { char enclosed with zero or more whitespace chars
  • (?P<entry>[^{}]*?) - Group "entry": any 0 or more chars other than { and }, but as few as possible
  • \s* - zero or more whitespace chars
  • } - a } char.
Related