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?

Drew
  • 29,895
  • 7
  • 74
  • 104

1 Answers1

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?

Community
  • 1
  • 1
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • 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... –  Jan 18 '15 at 04:44
  • 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. – lawlist Jan 18 '15 at 04:48