1、| 选择 ( )分组

  1. <script>
  2. // | 选择 ()分组
  3. var str = "你去哪里,他在..."
  4. var reg = /你去|他在/g;
  5. console.log(str.replace(reg,"*")) //*哪里,*...
  6. </script>

2、var reg = /^…..$/ 严格匹配 整个字符串必须满足正则

  1. <script>
  2. var phone = "02788667777"
  3. var reg = /(027)?8\d{7}/;
  4. var reg = /^(027)?8\d{7}$/; //严格匹配
  5. console.log(reg.test(phone))
  6. </script>