I want to replace below example
line1 
line2 
line3 
to:
line1 
line2 
line3 
which means:
- Do not replace line3 case (file name start with "/assets" already)
- Add "/assets/" to file name for line1 case (end with a space)
- Add "/assets/" to file name for line2 case also (end with a ')').
I try to use below code but it doesn't work.
(setq str "
line1 
line2 
line3 
")
(with-temp-buffer
(insert str)
(goto-char (point-min))
(setq regex1 "\\!\\[img\\](\\([^/]*?\\)\\([ \\|)]\\)")
(while (re-search-forward regex1 nil t)
(setq regex2 (format "))
(replace-match regex2 nil t))
(print (buffer-string))
)
But the result not correct:
line1 
line2 
Obviously, the ' ' and ')' has been replaced also. but I didn't include it in the match group.
regex2
isn't a regular expression (or certainly isn't being used as one), so that's unintuitive naming.