0
点赞
收藏
分享

微信扫一扫

Python Php正则表达式匹配字符串中的http链接


import re
pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') # 匹配模式

string = 'Its after 12 noon, do you know where your rooftops are? http://tinyurl.com/NYCRooftops '
url = re.findall(pattern,string)
print url

php如何写呢

function getJustUrl($inUrlText)
{
$parttern = "/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/";
preg_match($parttern, $inUrlText, $match);
return count($match) > 0 ? $match[0] : '';
}

 

举报

相关推荐

0 条评论