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

123456789101112131415161718192021222324252627282930313233343536
  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]/ //任意匹配abc
  12. // console.log(reg.test('abc'))
  13. // console.log(reg.test('abandon'))
  14. // console.log(reg.test('banana'))
  15. // console.log(reg.test('car'))
  16. // console.log(reg.test('listen'))
  17. // console.log(reg.test('tomorrow'))
  18. // 连字符
  19. // const reg1 = /[a-z]/;//a-z的26个字母任意匹配
  20. // const reg2 = /[A-Z]/; //A-Z的26个字母任意匹配
  21. // const reg3 = /[0-9]/; //0-9的数字任意匹配
  22. // const reg4 = /[a-zA-Z0-9_]/
  23. // . 除换行外的任意字符
  24. const reg = /./
  25. console.log(reg.test(''))
  26. console.log(reg.test('abc'))
  27. console.log(reg.test('\n'))
  28. console.log(reg.test('\r'))
  29. console.log(reg.test('34567'))
  30. </script>
  31. </body>
  32. </html>