开发者

Url Matching using Gruber's regex in PHP

how do I get the regex mentioned in this article working with preg_match in php?

<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]开发者_开发百科+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>

Using the code above I get the following error:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...


Try this:

preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);

You were missing the regex delimiters (usually /, but using # here because it's more convenient for URLs)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜