Last active
August 29, 2015 14:19
-
-
Save xuanfeng/8e4ff1fb6eab40c14ad5 to your computer and use it in GitHub Desktop.
正则表达式记录
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 部分替换 | |
需求: <link href="/" rel="canonical"> 需要将href替换成data-href | |
解决:通过()获取某一组固定字符串,用$1表示,再进行替换 | |
*/ | |
var str = '<link href="/" rel="canonical"><link href="/" rel="canonical"><link data-id="" href="/" rel="canonical">'; | |
res = str.replace(/(link.*?)href/ig, '$1data-href'); | |
/* 身份证号 | |
需求:检测身份证号正确性 | |
解决:身份证号长度为15-18,最后一位可能为x或X | |
*/ | |
reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ | |
/* 域名检测 | |
需求:检测是否为正确域名,包含端口 | |
*/ | |
reg = /^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?(:\d{1,4})?$/ | |
// HTTP支持所有端口、HTTPS不支持443端口 | |
reg = /^https?:\/\/[\w.]+(:(?!443\b)\w+)?(\/\w*)?$/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment