ajsie
ajsie

Reputation: 79776

Omit a pattern?

is there a way to tell preg_match_all to find all sequences that matches a certain pattern but omits another pattern?

eg.

<a>computers</a>
<a>books</a>
<a>pens</a>

i want to match books and pens but not computers.

so using:

preg_match_all('/<a>.*?<\/a>', $string, $array);

wont do.

would appreciate some help with this. thanks!

Upvotes: 1

Views: 155

Answers (1)

outis
outis

Reputation: 77420

You can use lookahead assertions:

/<a>(?!computer).*?<\/a>/

Upvotes: 4

Related Questions