5.元字符-字符类.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // [] 任意匹配
  11. // const reg = /[abc]/;
  12. // console.log(reg.test("ababab"));
  13. // console.log(reg.test("abc"));
  14. // console.log(reg.test("acbacb"));
  15. // console.log(reg.test("acacac"));
  16. // console.log(reg.test("dfdfdfd"));
  17. // 连字符 -
  18. // const reg1 = /0-9/;//匹配数字
  19. // const reg2 = /a-z/;//匹配小写英文字母
  20. // const reg3 = /A-Z/;//匹配大写英文字母
  21. // const reg4 = /a-zA-Z0-9_/; //匹配英文字母+数字+下划线
  22. // ^ 取反
  23. const reg6 = /\d/;
  24. console.log(reg6.test("aaa"));
  25. // . 除换行以外的任意字符
  26. // const reg7 = /./;
  27. // console.log(reg7.test("aaa"));
  28. // console.log(reg7.test("1234567890"));
  29. // console.log(reg7.test(""));// false
  30. // console.log(reg7.test("\n"));
  31. // console.log(reg7.test("\r"));
  32. </script>
  33. </body>
  34. </html>