I'm looking for a grep for JavaScript function names including parenthesis.
Example: myfunction()
I need it to ignore jQuery events like .on()
, .click()
, .width()
as well. So basically "get word before parenthesis and parenthesis but not if there is a .
before the word". I tried different stuff like ([\l\u]())
but i can't get my head around. Any Ideas?
To match a phrase where something may not appear "before" it, use a negative lookbehind:
(?<!\.)\b([\l\u]+\(\))
One possible problem in your own attempt may have been that you only test a single character before the parentheses; another may have been you did not escape the (literal!) parentheses.
This matches myfunction()
and even myFunction()
, but nothing more. A larger commonly used set of characters in function names would be:
(?<!\.)\b([_\l\u]\w*\(\))
Note that this ignores any and all arguments that may appear inside the parentheses (as per your specification, or so it would seem). Unfortunately, that is not easily added since you can not match "matching parentheses" with a single GREP.