Ich versuche, einen regulären Ausdruck zu schreiben, um alle JavaScript-Methodendefinitionen in einer Konstruktorzeichenfolge übereinzustimmen.Regulärer Ausdruck, um alle Methoden in einem Stück Code zu finden
//These two should match
this.myMethod_1 = function(test){ return "foo" }; //Standard
this.myMethod_2 = function(test, test2){ return "foo" }; //Spaces before
//All of these should not
//this.myMethod_3 = function(test){ return "foo" }; //Comment shouldn't match
/**
*this.myMethod_4 = function(test){ return "foo" }; //Block comment shouldn't match
*/
// this.myMethod_5 = function(test){ return "foo" }; //Comment them spaces shouldn't match
/*
* this.myMethod_6 = function(test){ return "foo" }; //Block comment + spaces shouldn't match
*/
this.closure = (function(){ alert("test") })(); //closures shouldn't match
Der reguläre Ausdruck sollte übereinstimmen ['myMethod_1', 'myMethod_2']. Der reguläre Ausdruck sollte nicht übereinstimmen ['myMethod_3', 'myMethod_5', 'myMethod_6', 'closed'].
Hier ist, was ich bisher habe, aber ich habe Probleme mit denen, die in Kommentaren:
/(?<=this\.)\w*(?=\s*=\s*function\()/g
Ich habe diese kühlen site benutzen es zu testen.
Wie löse ich das?