0

I have a large number of files that need to get a certain function call removed entirely. The first thing that I did was use find-dired to generate a dired list of files from find's output:

find . \( -type f -exec egrep -q -i -e "awesomeMethod\(\s*true\s*\)" \{\} \; \) -ls

Now I have a lot of files. So I hit t to toggle all of them and they become highlighted. Then I hit Q, which brings up query-replace-regex for all marked files. I don't know what the variable is called in each file that I'm getting rid of this call for, e.g., it could be removing $a->awesomeMethod(true); or $betterVariableName->awesomeMethod(true);, so I need a real regex. I was thinking \S+\->awesomeMethod\(\s*?true\s*?\) or something, and replacing it with nothing. I know that's definitely not perfect -- it's a context free grammar :-P -- but it will get me close.

I was surprised when this regex didn't match anything, since it's almost the same as the regex that generated my list of files. Then I saw that even awesomeMethod\(true\) didn't match anything, when I was looking right at something it should match. Thinking that maybe I would have to double-escape the parenthesis because of lisp (even though I'm doing this interactively), I tried awesomeMethod\\(true\\) which again didn't match. Then, surprisingly, awesomeMethod(true) did match, when that is obviously not supposed to in a regex since (...) denotes a capture group. M-S-% on a single file gives the same result.

What am I doing wrong? Emacs 24.3.

0

1 Answer 1

2

Parenthesis in emacs regular expressions are taken literally unless they're escaped with backslashes (then they denote capture groups).

Here's a link for more information: http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html

Sign up to request clarification or add additional context in comments.

1 Comment

Nice, I ended up needing \S +awesomeMethod(true)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.