2.边界符.html 846 B

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. // 1. \b 单词边界
  11. let reg = /\ban\b/ig;
  12. let str1 = 'an Cat, is Lan Animal';
  13. console.log(str1.match(reg));
  14. // const a = {
  15. // b: 12
  16. // }
  17. // a.b = 11
  18. // console.log(a)
  19. // 2. ^ 匹配字母首行
  20. let reg1 = /^ab/;
  21. let str2 = 'abbc';
  22. // console.log(reg1.test(str2))
  23. // 3. $ 匹配字母尾行
  24. let reg3 = /ab$/
  25. // console.log(reg3.test("ababbaa"))
  26. let reg4 = /^a$/;
  27. console.log(reg4.test("aaa"))
  28. console.log(reg4.test("a"))
  29. console.log(reg4.test(" "))
  30. </script>
  31. </body>
  32. </html>