代码之家  ›  专栏  ›  技术社区  ›  Michael Galos

postscript代码的正则表达式

  •  0
  • Michael Galos  · 技术社区  · 14 年前

    我需要它抓住括号中的9位数字,前提是前面出现了“6/Helvetica粗体f”,而不是“6/Helvetica f”

    6 /Helvetica-Bold f
    6 /Helvetica
    <-- any number of lines of other text -->
    261 632 m(436243874)r 1 9 0 Endline    <--- this would not match
    6 /Helvetica-Bold f
    <-- any number of lines of other text -->
    261 632 m(436243874)r 1 9 0 Endline    <--- this would match
    

    我发现这个--“6/Helvetica-Bold[\s\s]+((\d\d\d\d\d\d\d\d))”并不好,因为它将匹配上面所示的两种情况。
    有人能帮我吗?快把我逼疯了?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Tim Pietzcker    14 年前
    6\s*/Helvetica-Bold f(?:(?!6\s*/Helvetica)[\s\S])+\((\d{9})\)
    

    应该有用。

    说明:

    6\s*/Helvetica-Bold f     # match 6 /Helvetica-Bold f
    (?:                       # match the following as many times as possible
     (?!6\s*/Helvetica)       # (as long as it's not possible to match 6 /Helvetica here
     [\s\S]                   # match any character
    )+                        # at least once
    \(                        # match a literal (
    (\d{9})                   # match and capture 9 digits
    \)                        # match a literal )