【问题标题】:Matching ASN.1 string with python regexp使用 python regexp 匹配 ASN.1 字符串
【发布时间】:2020-12-24 02:40:37
【问题描述】:

如何将这个 ASN.1 字符串与 python regexp 匹配

"::= { bgpPathAttrEntry 6 }"

我试试这个正则表达式:

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

然后失败。

【问题讨论】:

  • 我使用的正则表达式是:\n\s+::=\s*{\s*(?P\S+\s\d+)}\n
  • 试试::=\s*{\s*(?P&lt;entry&gt;[^{}]*?)\s*},见demo
  • 将前导的\s+ 更改为\s* 并在} 之前添加\s*,例如\s*::=\s*{\s*(?P&lt;entry&gt;\S+\s\d+)\s*} regex101.com/r/0zEXiT/1
  • 非常感谢维克多!现在好了!

标签: python regex asn.1


【解决方案1】:

你可以使用

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

regex demo

详情

  • ::= - 文字子串
  • \s*{\s* - { 用零个或多个空格字符括起来的字符
  • (?P&lt;entry&gt;[^{}]*?) - 组“条目”:除 {} 之外的任何 0 个或多个字符,但尽可能少
  • \s* - 零个或多个空白字符
  • } - } 字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多