The emacs function reprograms the cross-interpretation of \ (\) wildcards literally in regexp

I have successfully used replace-regexp interactively to replace every instance of quoted text in the buffer below using the non-command version. The regular expression that I was looking for was

\"\([^\"]*\)\" 

and introduced NEWTEXT I was \ 1.

* "PROJECT START"
:PROPERTIES:
:ID: 1
:Unique_ID: 17
:DURATION: "0 days"
:TYPE: "Fixed Work"
:OUTLINE_LEVEL: 1
:END:

The interactive text aboe has been converted to the text below.

* PROJECT START
:PROPERTIES:
:ID: 1
:Unique_ID: 17
:DURATION: 0 days
:TYPE: Fixed Work
:OUTLINE_LEVEL: 1
:END:

I tried to do the same search and replace programmatically by inserting the following two lines

(while (re-search-forward "\"\([^\"]*\)\"" nil t)
  (replace-match "\1" nil nil ))

at the top of the buffer and executes, but it just returned zero without finding any matches.

When i lower

\( \) 

grouping and replacing \ 1 with \ &

(while (re-search-forward "\"[^\"]*\"" nil t)
  (replace-match "\&" nil nil ))

I get every line replaced by '&'.

* &
:PROPERTIES:
:ID: 1
:Unique_ID: 17
:DURATION: &
:TYPE: &
:OUTLINE_LEVEL: 1
:END:

, , , , .

- , \&,\N,\ ?

+5
1

"\" "(", ")" "\ 1". :.

(while (re-search-forward "\"\\([^\"]*\\)\"" nil t)
  (replace-match "\\1" nil nil ))
+7

All Articles