Elisp:无法从正则表达式中获取匹配的组

Elisp: can't get matched group from regex

代码:

(if 
      (string-match-p "\(.*\)/www/sites" 
                      "/var/www/lwt/www/sites/all/modules/bundles/bundles.module")
      (match-string-no-properties 1 
                      "/var/www/lwt/www/sites/all/modules/bundles/bundles.module")
      "false"
)

这里我希望得到“/var/www/lwt”,但我得到了nil。怎么了?

正如其文档字符串告诉您的那样:

string-match-p is a compiled Lisp function in `subr.el'.

(string-match-p REGEXP STRING &optional START)

Same as `string-match' except this function does not change the match data.

所以你应该使用 string-match