3

Q: how do I extract an org-mode link label?

Given an org-mode internal link with the following format:

[[link-target][link-label]]

How do I extract link-label?

I need to process the link as a string, not interactively in an org-mode buffer. I could write a regexp to do this, but am wondering if there's a function already built in.

2 Answers 2

3

You want something like this. The regexp you want is already defined in the variable org-bracket-link-regexp.

(let ((s "[[link-target][link-label]]"))
  (string-match org-bracket-link-regexp s)
  (list
   (match-string 1 s)
   (match-string 3 s)))

This should return a list of ("link-target" "link-label")

0

org-copy-visible, bound to C-c C-x v, should do the job for you.

1
  • Unfortunately, that won't work for my use case, which is to process a string. I've updated the question.
    – Dan
    Commented Feb 20, 2017 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.