Subject: bug#45973: replace-regexp lisp replacement bug

From: Nicholas Drozd <[email-masked]>
Date: Tue, 19 Jan 2021 16:36:20 -0600

Thanks for the quick turnaround. I've included a patch to add a test for this.
From d7bed718a5a88cc834456ac8d2e39ffc4f07e292 Mon Sep 17 00:00:00 2001
From: Nick Drozd <[email-masked]>
Date: Tue, 19 Jan 2021 16:26:02 -0600
Subject: [PATCH] * test/lisp/replace-tests.el: Add nested match group test

---
 test/lisp/replace-tests.el | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index 8c2682a1f1..2db570c97d 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -587,5 +587,18 @@ occur-highlight-occurrence
                               (get-text-property (point) 'occur-target))
           (should (funcall check-overlays has-overlay)))))))
 
+(ert-deftest replace-regexp-bug45973 ()
+  "Test for https://debbugs.gnu.org/45973 ."
+  (let ((before "1RB 1LC 1RC 1RB 1RD 0LE 1LA 1LD 1RH 0LA")
+        (after  "1LB 1RC 1LC 1LB 1LD 0RE 1RA 1RD 1LH 0RA"))
+    (with-temp-buffer
+      (insert before)
+      (goto-char (point-min))
+      (replace-regexp
+       "\\(\\(L\\)\\|\\(R\\)\\)"
+       '(replace-eval-replacement
+         replace-quote
+         (if (match-string 2) "R" "L")))
+      (should (equal (buffer-string) after)))))
 
 ;;; replace-tests.el ends here
-- 
2.17.1