开发者

Select rows that are not urls using regexp?

I've tried multiple regexp's but still fetching rows that contains urls.

$fields=array(
":regexp"=>"/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/"
);

$foo=$sql->prepare("SELECT *开发者_如何学Python FROM names WHERE name NOT REGEXP :regexp");
$foo->execute($fields);


Try the regex .*?:\/\/[^ ]*?\.[^ ]*


are you using mysql? if so, the regex syntax is not PCRE (like your regex appears to be). it does not use the / delimiters.

also, if you're only testing for the existence of common urls, why isn't the domain part sufficient?

'[a-z]+://([a-z0-9]+(-+[a-z0-9]+)*\.)+[a-z]{2,}'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜