Emacs add quotes around every word
Asked Answered
Q

3

5

I have a file and i want to add quotes around every word for example hello becomes "hello" So far i have tried this in emacs:

M-x query-replace-regexp [a-z]+ RET "\1" y

But it just deletes the word and leaves quotes.

Quipster answered 8/6, 2014 at 15:53 Comment(2)
That's because you're replacing the regexp by the string?Benenson
yeah, but how do i tell him not to delete the regexp? jus to add qoutes aroundQuipster
P
6

This is what you want:

M-x query-replace-regexp \(\<\w+\>\) RET "\1" y
Peneus answered 8/6, 2014 at 16:0 Comment(0)
M
5

You need to place a capturing group ( ) around your pattern referencing to back reference \1

M-x query-replace-regexp \([a-zA-Z]+\) RET "\1" y
Maduro answered 8/6, 2014 at 16:18 Comment(0)
Q
3

ok i got it, instead od the \1 I need to put \& in the replace part

Quipster answered 8/6, 2014 at 16:0 Comment(1)
Or use \(...\), as in the example I gave. You also need to check word boundaries, using \<...\>. And you can use \w to represent any word char.Peneus

© 2022 - 2024 — McMap. All rights reserved.