有人能告诉我错误是在我的正则表达式行

Can somebody please tell me where the error is in my regex line?

本文关键字:我的 正则表达式 错误 告诉我      更新时间:2023-09-26

我发现了这个模式:

(?<=module.exports = function routes'(') {'n)['S's]*?(?='n})

选择此文本中花括号内的文本:

module.exports = function routes() {
  this.root('pages#main');
  this.get('/dashboard', 'pages#dashboard');
}

谁能告诉我为什么这是无效的?:

myVar = data.match(/(?<=module.exports '= function routes'(') {'n)['S's]*?(?='n})/);

如果toString()在你的上下文中工作,那么这个也应该工作

var str = module.exports.toString();
str = str.replace(/function [^ ]+'(')'s*'{/, '').replace(/'}$/,'');