给定一个字符串,我希望能够将其中所有的链接替换为该链接的描述。例如,给定以下内容:
this is a [[http://link][description]]
我想要返回
this is a description
我使用re-builder构建了这个链接的正则表达式:
\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]
这是我的函数:
(defun flatten-string-with-links (string)
(replace-regexp-in-string "\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]"
(lambda(s) (nth 2 (split-string s "[\]\[]+"))) string))
它不是替换整个正则表达式序列,而是只替换尾部的“]]”。它产生的结果如下:
this is a [[http://link][descriptiondescription
我不明白出了什么问题。非常感谢任何帮助。
更新:我已经改进了链接的正则表达式。这与问题无关,但如果有人要复制它,他们可能会得到更好的版本。