royskatt
royskatt

Reputation: 1210

PCRE - Negative Lookahead

I want to match whole lines, here an example set:

/jome/stat/d-heme-sdfsdf/ertert ***# NOT wanted***
/jome/stat/d-heme-sdfsdf # WANTED
/jome/stat/d-gome-sdfsdf/qeqwe # NOT wanted

So I did:

(e|d|b)-(heme|gome|jome)-(.+)(?!\/)

Unfortunatly, it still matches the unwanted lines. Where is the mistake?

Upvotes: 0

Views: 1023

Answers (2)

Avinash Raj
Avinash Raj

Reputation: 174696

If you want to use negative lookahead then place it before (.+) and don't forget to add .*? inside the negative lookahead.

(e|d|b)-(heme|gome|jome)-(?!.*?\/)(.+)

DEMO

Upvotes: 1

Amit Joki
Amit Joki

Reputation: 59232

You don't require negative lookahed. . was matching / as well.

(e|d|b)-(he|go|jo)me-[^\/]+$

Upvotes: 2

Related Questions