Hi,
I am trying to write a regex to match all the javascript method definitions in a constructor string.
//These two should match
this.myMethod_1 = function(test){ return "foo" }; //Standard
this.myMethod_2 = function(test, test2){ return "foo" }; //Spaces before
//All of therse 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
The regex should match ['myMethod_1', 'myMethod_2'] The regex should not match ['myMethod_3', 'myMethod_5', 'myMethod_6', 'closure']
Here's what I have so far, but I am having problems with the ones that appear in comments:
/(?<=this.)\w*(?=\s*=\s*function()/g
I've been using this cool site to test it.
Does anyone have any ideas how to solve this.
Regards,
Chris