Regex if you want to ensure URL starts with HTTP/HTTPS:(正则表达式是否要确保URL以HTTP / HTTPS开头:)
https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&//=]*)
If you do not require HTTP protocol:(如果您不需要HTTP协议:)
[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&//=]*)
To try this out see http://regexr.com?37i6s , or for a version which is less restrictive http://regexr.com/3e6m0 .(要尝试此操作,请访问http://regexr.com?37i6s ,或使用限制性较弱的http://regexr.com/3e6m0版本。)
Example JavaScript implementation:(JavaScript实现示例:)
var expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; var regex = new RegExp(expression); var t = 'www.google.com'; if (t.match(regex)) { alert("Successful match"); } else { alert("No match"); }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…