想简单写个压缩js文件的方法,在使用正则时遇到了问题。
let newStr = str.replace(/(?<!(var|let|const|function))\s/g, '');
该正则在浏览器上正常,但在node.js中就报错
let newStr = str.replace(/(?<!(var|let|const|function))\s/g, ''); ^ SyntaxError: Invalid regular expression: /(?<!(var|let|const|function))\s/: Invalid group at Object.<anonymous> (c:\Users\Administrator\Desktop\test2\test2.js:6:17) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Function.Module.runMain (module.js:609:10) at startup (bootstrap_node.js:158:16) at bootstrap_node.js:598:3
GCT1015
相关分类