0

I am trying to develop a regex to check if points is within a GitHub markdown link to a wiki page, and then extract that page name. For example

some text [link_name](https://github.com/user/wiki/Tool-info) more text

If point is between the [ and the ) and the user clicks a keyboard shortcut, I would like to extract the name of the wiki page, namely Tool-info..

Here is what I have:

(defun test-wiki ()
  (interactive)
  (let ((name nil) (m-beginning nil))
    (save-excursion
      (if (char-equal (char-after) ?\[)
          (setq m-beginning t)
        (when (looking-back "\\[[^)]*?" (line-beginning-position))
          (setq m-beginning t)
          (goto-char (match-beginning 0))))
      (when m-beginning
        (when (looking-at "\\[[\\w]+?\\](\\([:/.\\w]+?\\))")
          (setq name (match-string 1)))))
    (if name
        (message name)
      (message "No match"))))

Currently, this gives message "No match" in all cases..

0

You cannot use \w inside a character class in Emacs, instead you can use:

(when (looking-at "\\[\\w+?\\](\\([-:/.[:alnum:]]+?\\))")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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