class类名是变量,所以要用new RegExp
这是我写的一部分,但匹配不全:
var str = 'asfsdf class Bop { public double breadth; public double height; static void get(){ var test = asas; var ssasd = function(){} } static void set(){} } class Boxtester { static void Main(string[] args) { Box Box1 = new Box(); Box Box2 = new Box(); double volume = 0.0; // Box1 详述 Box1.height = 5.0; Box1.length = 6.0; Box1.breadth = 7.0; } }';
//要匹配出来的字段是
//class Bop { public double breadth; public double height; static void get(){ var test = asas; var ssasd = function(){} } static void set(){} }
var word = 'Bop';
var res = new RegExp("class\\s+"+word+"\\s*\\{(\\s+(.+?)\\s+)*\\}","g");
console.log(res.exec(str))
求教各位大神!