<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>5个内部类</title>
</head>
<body>
<script>
//两种书写正则表达式的风格
//1.
// var redExp = /\d/;
//2.RegExp
// var regExp = new RegExp('/\d/');
//g -----> 表示所有
// 预定义类
console.log("-------------------------------")
// \d [0-9] 数字字符
// \D [^0-9] 非数字字符
// \s [ \t\n\x0B\f\r] 空白字符
// \S [^ \t\n\x0B\f\r] 非空白字符
// \w [a-zA-Z_0-9] 单词字符
// \W [^a-zA-Z_0-9] 非单词字符
var regExp1 = /\s/g;
var str1 = "hello world 你好 世界 !"
console.log({str1:str1})
//trim() 去掉字符串前后的空白字符
var res1 = str1.trim();
console.log({res1:res1})
console.log(regExp1.test(str1)) //true
//replace() 替换
var s1 = str1.replace(regExp1,"");
console.log({s1:s1})
//简单类
console.log("-------------------------------")
var regExp2 = /fuck/;
var str2 = "风景很美, fuck, 手机丢了";
var res2 = str2.replace(regExp2,"***");
console.log({str2:str2});
console.log({res2:res2});
console.log(regExp2.test("fucks aaa")); //true
console.log(regExp2.test("fuc aaa")); //false
console.log(regExp2.test("aaa")); //false
// 负向类
console.log("-------------------------------")
var regExp3 = /[^0-9]/; //表示非数字
console.log(regExp3.test("abc")); //true
console.log(regExp3.test("123566")); //false
//边界
var regExp4 = /^[0-9]/; //表示以数字字符开始的字符串
console.log(regExp4.test("123abc")); //true
console.log(regExp4.test("abc123")); //flase
console.log(regExp4.test("abc123efg")); //false
//范围类
console.log("-------------------------------")
//a,b,c....y,z [a-z]
var regExp5 = /[a-f]/; //包含a-f的其中一个字符
console.log(regExp5.test("abc123")); //true
console.log(regExp5.test("123abcf")); //true
console.log(regExp5.test("123hijklmn")); //false
//组合类
console.log("-------------------------------")
var regExp6 = /[a-f1-5]/; //包含字符a-f和1-5
console.log(regExp6.test('hijk789a')); // true
console.log(regExp6.test('hijk789')); // false
console.log(regExp6.test('hijk7895')); // false
</script>
</body>
</html>