We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

3

No, regplace-regexp-in-string does not magically substitute the buffer string into the STRING argument. It is a function but not a command (does not have an interactive specification). The command you are actually looking for is query-replace-regexp which can be used interactively and is bound to C-M-%. Use: C-M-% [0-9] RET \,(string (+ (string-to-char \&...


0

The query-replace-regexp does the job.


1

You could use iedit for that. image source: iedit github repository You should select your block of code and activate iedit-mode (C-;) to edit it. When Iedit mode is turned on, all the occurrences of the current region in the buffer (possibly narrowed) or a region are highlighted. If one occurrence is modified, the change are propagated to all ...


2

The following example of stupid but valid C++ code shows that automatic replacement of throw EXPRESSION; by throw new Error(EXPRESSION); is not possible in a roboust way without exploiting lexical information from the buffer. The comments in the source code indicate the problems. #include <string> int main() { try { throw /* some comment ...


2

What you need to use is regexp groups. In short, if you put something inside parenthesis in your regexp, you can reuse what's inside the parenthesis when replacing by using \1 (or \n if you have multiple groups). In your case, it would be throw "\(.*\)" -> throw new Error("\1"). The package pcre2el makes it easier to work with regexp groups, you can also ...


2

You can use M-x replace-regexp or M-x query-replace-regexp. e.g.: C-M-% throw \(".*?"\); RET throw new Error(\1); RET If "some message" might contain escaped double-quotes like "whoops, \"foo\" happened" then the pattern needs to be more complex; something more like: throw \(""\|".*?[^\]"\); And if there might be embedded newlines as well, . doesn't ...


Top 50 recent answers are included