reddit / emacs

Is search and replace on regexes possible in Emacs, or Vim for that matter? Not that I use Vim, but I use evil-mode.

vfclists · 2022-06-15 18:47
I suspect it is possible only my regex-fu is weak. I want to delete all quoted strings in a region, ie `"Any text goes here"`, but I can't seem to get the regex right. How can I write the regex in mode, ie `:<,>s/regex//g`? Is it because I may be falling foul of the double slash escapes in Emacs regexes? `:<,>s/"\\.*\"//g`
marlgl · 2022-06-15 19:42
Try this: `:'<,'>s/"[^"]*"//g`. You don't need to escape the dot and are escaping one quotation mark and not the other. See [emacs regexps on wiki](https://www.emacswiki.org/emacs/RegularExpression).
lovela47 · 2022-06-23 16:47
I'm not familiar with evil-mode regexps, but: you can interactively test a regexp on your current buffer using `M-x re-builder`. It will highlight all the matches. And it will fail to match stuff until you add/remove the right number of slashes. I have never really bothered to learn Elisp's weird regexp quoting rules because it's so easy to test stuff using `re-builder`