I have a regex which I’m using to match user functions inside an IDE (Sublime). This matches what I want (the function name itself), but it also matches the first parentheses. Therefore the match is like follows:
this._myFunction(‘content’);
Notice the opening paran.
Here is my expression:
(?:[^\._])?([\w-]+)(?:[\(]){1}
How can I exclude the opening paran from getting matched?
.
As a bonus question: How can I successfully not match the string: function, because as you can expect function( matches (not fun in JS).
Thank you to anyone who can assist.
Unfortunately, you cannot really use regex to parse any context-free grammar, but hopefully this can do better. It uses positive lookahead to not include the opening paren in the match but look for it anyways:
If your IDE’s regex engine supports negative lookbehind (the subexpression is not found before the match), you can avoid matching the string ‘function’ or “function”: