Regex Preg_match Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
darkchaz
Forum Newbie
Posts: 1
Joined: Mon Jun 09, 2008 12:55 pm

Regex Preg_match Issue

Post by darkchaz »

The odd part, is to test my regex patterns, I use dreamweaver's search function and check the option "use regex", and when I test it there, the pattern matches as expected.

Here is a brief example of what code I'm using:
<?php

$content = 'Anti-CD22 immunotoxins consist of a disulfide-linked FV (V<sub>H</sub>/V<sub>L</sub> ) antibody fragment recombinantly linked to a <a href="#">toxic<a> moiety capable of killing cells. <br><br> <b>Application:</b> These immunotoxins have been shown to have activity against various forms of cancer.';

$regex = '/<(?!br|a|sub|\/)/';

preg_match_all($regex, $content, $end_match);

$pos = strpos($content,$end_match[0][0]);
$result = substr($content,0,$pos);

?>
The code above seems to only match the "<" and ignores the regex saying not to match if the next characters are "br", "a", "sub", or "/". So the above code cuts off at the first <sub>, although, when i test searching the same content in dreamweaver with regex enabled, it stops at the first <b> in front of applications-- just as i expect it to.

Any ideas as to what could cause this?

Thank you!
Post Reply