1、备选字符集

  1. [] 里的内容也是或的关系
  2. [abc] abc
  3. [0-9] 数字0-9
  4. [a-z] 字符a-b
  5. [A-Z] 字符A-Z
  1. var str = 'desdjl932j388Tm'
  2. var reg = /[0-9]/g
  3. console.log(str.replace(reg,"*"));//desdjl***j***Tm
  4. console.log(str.replace(/[A-z]/g,"*"));//******932*388**

2、预定义字符集

  1. \b [0-9]
  2. \w [0-9A-z_]
  3. \s 空格
  4. . 表示所有的字符
  1. var str = "35453adasdfa"
  2. var reg = /\d/g
  3. console.log(str.replace(reg,"*"));//*****adasdfa
  4. var a = "hello_world1234WS"
  5. console.log(a.replace(/\w/g,"*"));//*******************
  6. console.log(a.replace(/./g,"*"));//****************
  7. var a = "hello.world"
  8. var reg = /\./
  9. console.log(a.replace(reg,"*"));//hello*world