常用正则表达式

127 阅读1分钟

1.匹配任意字符串将除了首位和末位之外的字符串替换成*。 例如:输入你好,hello => 你***o

let str = "你好,(hello),好的";
let regex = /^(.{1}).*(.{1})$/g;
let result = str.match(regex);
console.log(str.replace(regex,"$1***$2")) //你***o