<!-- 匹配数字-->
const reg1=/[a-zA-Z]/
// 匹配数字
const reg2=/\d/
//匹配非数字
const reg3=/\D/
//空格
const reg4=/\s/
// 字母,数字,下划线
const reg5=/\w/
// 特殊字符
const reg6=/[!@#$%^&*]/
//非字母匹配
const reg7=/[^a-zA-Z]/
// *************************正则方法*********************************
//test()检测一个字符串是否与正则表达式匹配,返回布尔值
const reg8 = /hello/
const str1 = 'hello,world'
console.log(reg8.test(str1))
//match方法,在字符串中搜索匹配正则表达的内容,返回数组或null
console.log(str1.match(reg8))
//search在字符串中搜索匹配正则表达式的内容,返回匹配的索引或-1 负
const reg9 = /world/
console.log(str1.search(reg9))//-1代表找不到
//replace()将匹配正则表达式的内容替换为指定字符串,并返回替代后的字符串
console.log(str1.replace(reg9,'1111'))
//split()根据正则表达式将字符串分割成数组
console.log(str1.split(/\s/))
// ******************************位置**********************************
// ^匹配字符串开始的位置
const str2='hello world'
const str3='AAAhello world'
const reg10=/hello/
const reg11=/^hello/
console.log(reg10.test(str2),reg10.test(str3))
console.log(reg11.test(str2),reg11.test(str3))
// 举例,匹配手机号
// const phoneNum='13312341234'
const phoneNum='13312341234ddddd'
// const phoneNUm='aaaa13312341234'
const phoneReg=/^1\d{10}$/
console.log(phoneReg.test(phoneNum))//$表示结束位置
// \b代表匹配单词边界
// \B非单词边界
const reg12=/\bworld\b/
console.log(reg12.test(str2))
const str4='helloworld'
console.log(reg12.test(str4))