本文介绍了使用javascript检查字符串是否包含字符串中的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查字符串是否包含使用javascript的网址我从谷歌获取此代码
I want to check if string contains a url using javascript i got this code from google
if(new RegExp("[a-zA-Z\d]+://(\w+:\w+@)?([a-zA-Z\d.-]+\.[A-Za-z]{2,4})(:\d+)?(/.*)?").test(status_text)) {
alert("url inside");
}
但这只适用于像和但它不适用于。此外,我想从字符串中提取该URL,以便我可以处理该URL。
But this one works only for the url like "http://www.google.com" and "http://google.com" but it doesnt work for "www.google.com" .Also i want to extract that url from string so i can process that url.
推荐答案
尝试:
if(new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(status_text)) {
alert("url inside");
}
这篇关于使用javascript检查字符串是否包含字符串中的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!