5.字符类.html 983 B

1234567891011121314151617181920212223242526272829303132333435
  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("ababba"));
  13. // console.log(reg.test("abc"));
  14. // console.log(reg.test("acbab"));
  15. // console.log(reg.test("acacaca"));
  16. // console.log(reg.test("ddfffdf"));
  17. // 连字符 -
  18. // const reg1 = /0-9/;
  19. // console.log(reg1.test('121s'));
  20. // // 取反 ^
  21. // const reg2 = /[^a-z]/;
  22. // console.log(reg2.test('32'));
  23. // . 匹配换行外的任意字符
  24. const reg3 = /./;
  25. console.log(reg3.test("Aaaa"));
  26. console.log(reg3.test("1234578765432"));
  27. console.log(reg3.test("")); // false
  28. console.log(reg3.test("\n"));
  29. console.log(reg3.test("\r"));
  30. </script>
  31. </body>
  32. </html>