如何使正则表达式否定


How to make this regex negation

我有以下代码:

$content = eregi_replace('!([a-zA-Z0-9]+)', '<a href="http://www.example.com/link/''1">''1</a>', $content);

这很好用,但我希望它能忽略重复的单词。

例如:

堆栈堆栈溢流溢出

他应该只得到第一个而忽略重复,这样就不会产生联系。

使用preg_replace()及其limit参数

$content = '!stack! stack! !overflow! !overflow';
$newcontent = preg_replace('#!([a-zA-Z0-9]+)#','<a href="http://www.example.com/link/''1">''1</a>',$content,1);