/^(http(s?)|):\/\/(.+)$/
複雜點為:
var urlregex = /(^(http|https):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/
或:
/((http|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/
當然這三種寫法不夠嚴謹,''與』'等明顯錯誤的url依然能匹配成功。
下面是比較嚴謹的一些寫法:涉及對http,https協議,網域名稱,ip,port的校驗。
常用正則校驗
郵箱 param s export function isemail s test s 手機號碼 param s export function ismobile s test s 號碼 param s export function isphone s 0 9 test s url位址 param...
python 部落格URL列表校驗
在構建了部落格列表之後,要做一些校驗,比如判斷有沒有重的或漏的,就要把url全部提取出來。import re fp open d in.txt r encoding utf 8 html fp.read all url re.findall str html re.ignorecase all ur...
Java手機正則校驗 及 其餘型別正則校驗
手機號校驗 大陸手機號碼11位數,匹配格式 前三位固定格式 後8位任意數 此方法中前三位格式有 13 任意數 15 除4的任意數 18 除1和4的任意數 17 除9的任意數 147 public static boolean ischinaphonelegal string str throws p...