5
給定一個字符串,我想用鏈接的描述替換它中的所有鏈接。例如,給定在emacs-lisp中,我該如何正確使用replace-regexp-in-string?
this is a [[http://link][description]]
我想回
this is a description
我用重新生成器來構建這個正則表達式中的鏈接:
\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]
這是我的函數:
(defun flatten-string-with-links (string)
(replace-regexp-in-string "\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]"
(lambda(s) (nth 2 (split-string s "[\]\[]+"))) string))
代替第整個正則表達式序列,它只替換尾部的「]]」。這是它生產的:
this is a [[http://link][descriptiondescription
我不明白髮生了什麼問題。任何幫助將非常感激。
UPDATE:我改進了鏈接的正則表達式。這與問題無關,但如果有人要複製它,他們可能會得到更好的版本。