Here is a simple test: #+begin_src org :file "test.org" ,#+NAME: hello1 ,#+BEGIN_SRC sh :var name="" echo "hello, $name" ,#+END_SRC ,#+BEGIN_SRC sh :noweb yes <> ,#+END_SRC ,#+NAME: hello2 ,#+BEGIN_SRC emacs-lisp :var name="" :results output (prin1 name) ,#+END_SRC ,#+BEGIN_SRC emacs-lisp :noweb yes :results output <> ,#+END_SRC ,#+BEGIN_SRC emacs-lisp :results output (prin1 "hi") ,#+END_SRC ,#+RESULTS: : "hi" #+end_src #+begin_src emacs-lisp :results output (defvar org-simple-ref-label-re (rx-to-string '(group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~")))) "Regexp for labels.") (defvar org-simple-ref-ref-label-regexps (list (concat ":ID:\\s-+" org-simple-ref-label-re "\\_>") ;; CUSTOM_ID in a heading (concat ":CUSTOM_ID:\\s-+" org-simple-ref-label-re "\\_>") ;; #+name (concat "^\\s-*#\\+name:\\s-+" org-simple-ref-label-re) ;; labels in latex (concat "\\\\label{" org-simple-ref-label-re "}") ;; A target, code copied from org-target-regexp and group 1 numbered. (let ((border "[^<>\n\r \t]")) (format "<<\\(?1:%s\\|%s[^<>\n\r]*%s\\)>>" border border border)) ;; A label link (concat "label:" org-simple-ref-label-re "\\_>") ;; code ref "[ ]*(\\(?2:ref\\):\\(?1:[-a-zA-Z0-9_][-a-zA-Z0-9_ ]*\\))[ ]*$" ;; noweb ref ":noweb-ref\\s-+\\(?1:.*?\\)\\s-" "\\\\lstset{.*label=\\(?1:.*?\\),.*}") "List of regular expressions to labels. The label should always be in group 1.") (with-current-buffer (get-buffer "test.org") (org-with-wide-buffer (goto-char (point-min)) (while (re-search-forward (string-join org-simple-ref-ref-label-regexps "\\|") nil t) (save-match-data (print (format "%s -> %s" (match-string-no-properties 0) (match-string-no-properties 1))) (org-element-context) ; <----- REASON!! cause `match-string-no-properties' result wrong. (print (propertize (match-string-no-properties 1) 'org-simple-ref--location (match-beginning 1))))))) #+end_src #+RESULTS[(2024-04-01 20:16:21) dc738972b5676dea6e0821cb02b2767219f4fd77]: #+begin_example " ,#+NAME: hello1 -> hello1" #("NAME" 0 4 (org-simple-ref--location 46)) "<> -> hello1(name=\"chris\")" #("hello1(name=\"chris\")" 0 20 (org-simple-ref--location 148)) " ,#+NAME: hello2 -> hello2" #("NAME" 0 4 (org-simple-ref--location 184)) "<> -> hello2(name=\"chris\")" #("hello2(name=\"chris\")" 0 20 (org-simple-ref--location 325)) #+end_example Found reason, check out the marker in the screenshot: