tags:

views:

35

answers:

1

I'm trying to write a regular expression for this.

I need it to grab the 9 digit number that's in brackets provided a '6 /Helvetica-Bold f' has appeared before it but not a '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

I found that this - "6 /Helvetica-Bold[\s\S]+((\d\d\d\d\d\d\d\d\d))" was no good as it would match for both cases as shown above.
Can anyone help it's driving me nuts?

A: 
6\s*/Helvetica-Bold f(?:(?!6\s*/Helvetica)[\s\S])+\((\d{9})\)

should work. (Re-edited to fit to edited example)

Explanation:

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 )
Tim Pietzcker
It doesn't seem to work, I think that's because it expects the 'Helvetica f' to be on the next line from 'Helvetica-Bold'
Mrgreen
Excellent! Thank you so much!
Mrgreen