开发者

Omit a pattern?

开发者 https://www.devze.com 2022-12-20 23:26 出处:网络
is there a way to tell preg_match_all to find all sequences that m开发者_C百科atches a certain pattern but omits another pattern?

is there a way to tell preg_match_all to find all sequences that m开发者_C百科atches 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!


You can use lookahead assertions:

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

精彩评论

暂无评论...
验证码 换一张
取 消