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

123456789101112131415161718192021222324252627282930313233343536373839
  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("acbcba"));
  15. // console.log(reg.test("acaacac"));
  16. // console.log(reg.test("dcdhjhfgjk"));
  17. // 连字符 -
  18. // const reg1 = /[0-9]/
  19. // const reg2 = /[a-f]/
  20. // 取反 ^
  21. // const reg3 = /[^a-z]/;
  22. // console.log(reg3.test("acaacac"));
  23. // console.log(reg3.test("uiuiui"));
  24. // console.log(reg3.test("ba8ba"));
  25. // console.log(reg3.test("as"));
  26. // . 除换行以外的任意字符
  27. const reg4 = /./;
  28. console.log(reg4.test('aaa'))
  29. console.log(reg4.test('123456789'))
  30. console.log(reg4.test(''));//false
  31. console.log(reg4.test('\n'))
  32. console.log(reg4.test('\r'))
  33. </script>
  34. </body>
  35. </html>