正则表达式
w3c参考地址:https://www.w3school.com.cn/jsref/jsref_obj_regexp.asp
要素:对象,方法,匹配规则
对象
- 正则对象
- 创建方式
let reg=new RegExp(pattern , [attr]) let reg2=/pattern/
- 创建方式
- String对象
方法
- 正则对象和字符串有各自的方法,调用方式不同
匹配规则
- [] 代表匹配任意 一个 字符
- [^] 这个里面的 ^ 代表非
- [ | ] 这个里面的 | 代表或
- s{n} 代表以s为标准匹配n个字符
s{n,m} 代表以s为标准匹配n到m个字符
s{n,} 代表以s为标准至少匹配n个字符 - () 代表一个节点,在已经匹配到的字符串中进行分割
let reg=/([0-9a-zA-Z]{1,})@([0-9a-zA-Z]{1,}\.com)/; let str='21000299@163.com'; let res=reg.exec(str);//["21000299@163.com", "21000299", "163.com", index: 0, input: "21000299@163.com", groups: undefned]