elisp 中查找主要使用 string-match 。它使用正则表达式来进行查找。elisp中没有C/C++中find 那样查询子串的缩进的函数。查询子串其实也可以利用正则表达式来处理 (string-match "Emacs Lisp" "This is Emacs Lisp Program") ;; ⇒ 8 该函数的第一个参数是一个正则表达式,上面代码中我们直接使用字符串进行匹配,...
string-match使用这个正则表达式进行文本匹配时,会将\\(和\\)包含的.+匹配到的文本段保存下来,需使用(match-string 1)提取。例如 (setq x "# Hello world! ") (setq r "^#[[:blank:]]+\\(.+\\)[[:blank:]]*$") (string-match r x) (princ\' (match-string 1 x)) 上述程序输出Hello world...
(progn (string-match "3\\(4\\)" "01234567890123456789") (message "%d" (match-beginning 0)) ;; => 3 (message "%d" (match-end 0)) ;; ⇒ 5 (message "%d" (match-beginning 1)) ;; ⇒ 4 (message "%d" (match-end 1))) ;; ⇒ 5 如果我们给出的参数超过了匹配组的大小,那么...
replace-match的最后一个参数表示替换哪一个捕获组,默认是0,例如上述的代码中,第0个捕获组就是整个字符串,所以它替换了整个字符串,我们可以将上述代码做一下修改 (let ((str "hello world 123")) (string-match "\\(hello world\\) \\([0-9]+\\)" str) (replace-match "\\2 \\1" nil nil str...
(defunswitch-extension(extension)(if(or(string-equalextension"h")(string-equalextension"hpp"))"cpp""h"))(defunswitch-file-name-extension(name)(concat(file-name-sans-extensionname)"."(switch-extension(file-name-extensionname)))(defunswitch-directory(directory)(cond((string-match".+/src/$"dire...
(if (string-match "^$" text) (empty-line text) (paragraph text))) Elisp 并未提供类似其他编程语言里if ... else if ... else这种条件表达式,因此上述代码是基于嵌套的if ... else ...表达式实现了三种情况的文本匹配及变换。 不过,Elisp 提供了cond表达式,它的逻辑与if ... else if ... else...
match-string 1 old-date)))也就是说,要想保留 重复时间间隔 部分的信息,要求输入的 TIME 符合 org-repeate-re 的正则表达式。而 org-repeate-re 的默认值为:org-repeat-re is a variable defined in ‘org.el’.Its value is"[[<][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^]>]*?\...
你的行动是: *string_buf_ptr = '\0';yylval.strval = strdup(string_buf_ptr)return STRING; 很明显,string_buf_ptr的strdup将返回空字符串的newly-allocated副本,因为您刚刚将string_buf_ptr指向的字符设置为0。 Two comments: 这个bug基本上与Flex(或Bison)无关。我知道,人们总是倾向于假设您使用的最不熟...
it should be a string to act on; this should be the string on which the previous match was done via ‘string-match’. In this case, ‘replace-match’ creates and returns a new string, made by copying STRING and replacing the part of STRING that was matched (the original STRING itself...
所以,例如package com.na.ip; import java.io.BufferedReader; import java.io.File; import java....