I’m trying to write a regex that will capture a function in JavaScript - although the language in which the function is written really doesn’t matter.
I have this JavaScript code:
function firstFunc(){ if(true){ alert('testF'); } elseif(false) alert('testf'); } function submitme(){ if(true){ alert('test1'); } elseif(false){ alert('test2'); } elseif(false){ alert('test3'); } } function submitmeAlso(){ if(true){ alert('test'); } elseif(false) alert('test'); }
I’m trying to capture the entire “submitme()” function from the word “function” all the way to the closing curly bracket of just that function.
I’ve come across a recursive pattern that will capture a pair of outer brackets and all nested ones, but once you add the beginning text - the word ‘function’, the function name, and the opening and closing argument brackets - problems ensue.
This may not be that hard, but I've had a heck of a time writing the right pattern.
Any help (an example pattern) would be greatly appreciated.
In reply to Recursive Regular Expression Help by me
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |