常见密码正则表达式
/^(?![0-9]+
)
(
?
!
[
a
−
z
A
−
Z
]
+
)(?![a-zA-Z]+
)(?![a−zA−Z]+)[0-9A-Za-z]{6,16}
/
其
中
(
?
!
[
0
−
9
]
+
/ 其中(?![0-9]+
/其中(?![0−9]+)表示排除掉只有数字的组合,
(?![a-zA-Z]+$)表示排除掉只有字母的组合,
[0-9A-Za-z]表示必须有字母或数字
(?!\d+ ) ( ? ! [ a − z ] + )(?![a-z]+ )(?![a−z]+)(?![A-Z]+KaTeX parse error: Undefined control sequence: \w at position 4: )([\̲w̲])+
例如,我的验证失败,其中包含;或[等字符。我对 white-listing 我的特殊字符不感兴趣,所以我用[^\w\s]作为测试 – 简单地把非字符(包括数字)和非空格字符放在一起。总而言之,这是对我有用的
至少8字符
至少1数字字符 (?=.?[0-9])
至少1小写字母 (?=.?[a-z])
至少1大写字母 (?=.?[A-Z])(
至少1特殊字符 (?=.?[^\w\s])
/(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\w\s]).{8,}$/ 简单演示涵盖各种情况
//密码强度正则,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符
var pPattern = /^.(?=.{6,})(?=.\d)(?=.[A-Z])(?=.[a-z])(?=.*[!@#
%^&*? ]).*
/;
//输出 true
console.log("=="+pPattern.test(“caibaojian#”));
^.(?=.{6,})(?=.\d)(?=.[A-Z])(?=.[a-z]).*$
"12345678901"金额每三位加一个逗号,千分
/\d(?=(\d{3})+$)/g
贪婪量词*
懒汉量词*?
分组回溯\1 \2,相当声明变量,方便后面引用。
<(\w+)>.*?</\1>
读取只有数字部分,并且拼接
‘3asdr34ere4-q887’.match(/\d/g).join(’’)
//“3344887”
变量用于正则表达式中
let hd = ‘houdunren.com’
let a = ‘.com’
eval(/${a}/
).test(hd)
lastIndex,当前str检索的索引
reg表达式用过一次后,lastIndex要设置为0
const str="haha haha";
const reg=/haha/g;
console.log(reg.test(str)); //打印 true
reg.lastIndex=0;
console.log(reg.lastIndex);
//打印0,
console.log(reg.test(str)); //打印 true
reg.lastIndex=0;
console.log(reg.lastIndex);
//打印0,
console.log(reg.test(str));
//打印 true
reg.lastIndex=0;
console.log(reg.lastIndex);
//打印0,