3.元字符-边界符.html 972 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // 单词边界 \b
  11. // const reg = /\bcat\b/g;
  12. // const str = 'This is a cat it is a scattered';
  13. // console.log(str.replace(reg,'dog'))
  14. // ^ 匹配字母行首
  15. // const reg = /^ac/i;
  16. // console.log(reg.test('acc'))
  17. // console.log(reg.test("bca"))
  18. // console.log(reg.test("Abca"))
  19. // $ 匹配字母行尾
  20. // const reg = /c$/;
  21. // console.log(reg.test('ccc'))
  22. // console.log(reg.test(''))
  23. // console.log(reg.test('cb'))
  24. // console.log(reg.test('ac'))
  25. const reg = /^a$/;
  26. console.log(reg.test('a a'))
  27. console.log(reg.test(''))
  28. console.log(reg.test('aba'))
  29. console.log(reg.test('bbb'))
  30. </script>
  31. </body>
  32. </html>