Using regex: Regular expression exeption on newest questions tagged regex – Stack Overflow

Hi is there anyone can help me with regular expression

This is the words that i want to replace

$text = '<a href="test-pregnancy.net">pregnancy<a> week by week, some time pregnancy can be very easy';
$search = 'pregnancy';
$replace = '<a href="google-pregnancy.net">pregnancy</a>';

print preg_replace('/('.$search.')/', $replace, $text);

is there any regular expression that except for words that contain inside a link? only replace words that not contain inside a link

I want it would be like this

$text = '<a href="test-pregnancy.net">pregnancy</a> week by week, some time <a href="test-pregnancy.net">pregnancy</a> can be very easy';

See Answers


source: http://stackoverflow.com/questions/8752228/regular-expression-exeption
Using regex: using-regex



online applications demo