roundrobin
roundrobin

Reputation: 716

Regex matching a word not followed by a string and allow multiple words (upto 5 words) in between

I'm trying to match a word ("Junior Consultant") not followed by a specific string "(m/f)" and allow multiple words (up to 5 words) in between.

Should match: Junior Consultant in New York Junior Consultant Banking Junior Consultant w1 w2 w3 w4 w5 Junior Consultant w1 w2 w3 w4 w5 w6 (m/f)

Should NOT match: Junior Consultant in New York (m/f) Junior Consultant (m/f) Junior Consultant w1 w2 w3 w4 w5 (m/f)

This is what I got so far: Junior Consultant((?!\s\(m\/f\))(\s\w+)){0,5}

Upvotes: 3

Views: 62

Answers (1)

GOTO 0
GOTO 0

Reputation: 47722

Almost there, but you have to match all zero to five words before the "(m/f)" part. Try this:

/Junior Consultant(?!(\s\w+){0,5}\s\(m\/f\))/

Upvotes: 3

Related Questions