1、只获取数字或字母

  1. <script>
  2. var str = "abc123";
  3. var reg = /[^abc]/g;
  4. console.log(str.replace(reg,"*"));
  5. var test = "?@hello123-";
  6. var reg = /[^\d]/g
  7. console.log(test.replace(reg,"*"))
  8. </script>

1.1、只获取数字

  1. <script>
  2. var str = "<span>2395人参观</span>-<span>46人评价</span>"
  3. var reg = /[^\d-]/g;
  4. var res = str.replace(reg,"");
  5. console.log(res.split("-"));
  6. </script>

2、过滤标签

var reg = /<[^<>]+>/g

  1. <script>
  2. var str = "<p>塞斯额啊</p><br/><span>666</span>"
  3. var reg = /<[^<>]+>/g //html标签的正则
  4. console.log(str.replace(reg,""))
  5. </script>