Reputation: 464
I'm writing a function list parser for Notepad++ to add support for Nasal.
I'm using the following regular expression:
^[\t ]*(var[\n\s]+)?([_A-Za-z]?[\w_]*)[\n\s]*=[\n\s]*func[\n\s]*(\([^\)\(]*\))?
: Debuggex Demo
... to match these 2 types of valid declarations:
foo = func...
var foo = func...
To further extract the function name foo
from the matches of this regex, the best I could come up with was:
(var[\n\s]+)?([_A-Za-z]?[\w_]*)
: Debuggex Demo
Using this matches "foo" or "var foo", as the case may be. What is a regex that can ignore the presence of the substring var[\n\s]+]
, so it only extracts "foo" for the function list?
Thanks a lot.
Upvotes: 0
Views: 259
Reputation: 89584
You can use the \K
feature that removes all on the left from the match result:
(?:var\s+)?\K([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)
(Note that this feature is only available in recent versions of np++)
Upvotes: 3
Reputation: 46871
Get the matched group from index 2.
(\bvar\b)?\s\s*(\w+)\s\s*=\s\s*func\b
Upvotes: 0