正则表达式:屁股字幕 - 匹配最后一个 \b 标签值

Regex : Ass subtitles - Match the last \b tag value

我想匹配 last \b 标签的数值,如果没有数字则为空字符串。

左边是字符串,右边是我要匹配的字符串:

\b                     Empty string
\b\b                   Empty string
\b1\b                  Empty string
\b\b1                  1
\b\b\i1                Empty string
\b1\blur0              1
\b2\b10anana           10
\b2\b1 0anana          1
\b2\bbanana10          Empty string

我目前受困于这个正则表达式 https://regex101.com/r/0TZeSn/1

(?<=\\s*b\s*)\d+(?!(?=\b))|(?<=\b)(?!.*\b).*?(?=\w|\)

来之不易

对于没有空匹配的匹配,您可以使用:

(?<=\ *b *)(?!\S*\b *(?!lur|ord|e))\d+

说明

  • (?<=\ *b *) 正面回顾,断言 \b 与左侧之间的可选空格
  • (?!负前瞻,断言不向右
    • \S*\b *(?!lur|ord|e) 匹配可选的非空白字符后跟 \b 而不是直接跟 lur orde
  • ) 关闭前瞻
  • \d+ 匹配 1+ 个数字

看到一个regex demo.

要同时获得空匹配,您可以匹配可选数字并在当前位置后直接断言不是 lur orde 并且在匹配 [=13= 后也不会断言]

(?<=\ *b *)(?!lur|ord|e|\S*\b *(?!lur|ord|e))\d*

再看一个regex demo.