0

This is my code statement

var myStr = require('ssh2')

and my elisp regex must return the arg value iff the statement has a require func invocation.

 (let ((s "var myStr = require('ssh2')"))
   (if (string-match "'require(\\([^']+\\)'" s)
       (match-string 1 s)))

this returns nil, however? what makes my regex a mess, someone?

0

1 Answer 1

2

How about?:

"require\(\\(?:'\\(.*\\)'\\)\)"

If you haven't already played around with M-x re-builder RET, you'll enjoy it.

Here is a link to one of my favorite threads regarding a noncapturing group:

What is a non-capturing group? What does a question mark followed by a colon (?:) mean?

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

2 Comments

it worked... but this pattern, "require\(\(?:'\(.*\)'\))" returned nil... the change i have made is put double slashes in the place of single slashes because somewhere i read in elisp, all escapes must be done twice...
I believe literal parentheses are single-escaped. Re-builder will fail if literal parentheses are double-escaped. Parentheses that are for grouping, are double-escaped. Your example contains an opening literal parentheses and a closing literal parentheses.

Your Answer

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