0

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:

  1. foo = func...
  2. 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.

2 Answers 2

3

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++)

Sign up to request clarification or add additional context in comments.

Comments

0

Get the matched group from index 2.

(\bvar\b)?\s\s*(\w+)\s\s*=\s\s*func\b

Online demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.