Given a string, I want to replace all links inside it with a link description. For example, given
this is a [[http://link][description]]
I would like to return
this is a description
I used re-builder to create this regex for reference:
\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]
This is my function:
(defun flatten-string-with-links (string)
(replace-regexp-in-string "\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]"
(lambda(s) (nth 2 (split-string s "[\]\[]+"))) string))
Instead of replacing the entire sequence of regular expressions, it replaces only the final "]]". This is what it produces:
this is a [[http:
I do not understand what is going on. Any help would be greatly appreciated.
The UPDATE . I improved the regex for the link. This is not relevant to the question, but if someone copies it, he may also get a better version.
source
share