postscript代码的正则表达式

时间:2010-09-27 07:31:57

标签: regex

我正在尝试为此编写正则表达式。

我需要它来抓住括号中的9位数字,前提是“6 / Helvetica-Bold 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 \ d))”并不好,因为它会如上所示匹配两种情况。
谁能帮助它让我疯了?

1 个答案:

答案 0 :(得分:0)

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 )
相关问题