简体   繁体   中英

Matching ASN.1 string with python regexp

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM