Do you know about save-match-data macro in Emacs Lisp?
October 16, 2023
(progn
(re-search-forward "foo")
(message "1. %s" (match-string 0))
(save-match-data
(re-search-forward "bar")
(message "2. %s" (match-string 0)))
(message "3. %s" (match-string 0)))