1 | let testRegex = /Code/ |
使用|匹配多个规则
1
/yes|no|maybe/
使用i忽略大小写
1
/ignorecase/i
.match()方法提取匹配项
1
2
3
4let ourStr = "Regular expressions";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns ["expressions"]使用g多次匹配
1
2
3let repeatRegex = /Repeat/g;
testStr.match(repeatRegex);
// Returns ["Repeat", "Repeat", "Repeat"]使用.匹配任意一个字符
使用[]单个字符匹配多种可能性
1
/b[aiu]g/
使用-单个字符匹配连续范围
1
/[a-e]at/