lundi 4 juillet 2016

How to do special regex find and replace in emacs


If anyone can tell me how to do this in emacs, it would save me a TON of time: I want to do a find and replace, but save what I "find" to put in the "replace". Basically, I have a bunch of print statements throughout my file. I redefined print to verboseprint(), which prints when the verbose flag is present when my script is run. However, since I'm using python 2.4, I was calling my print statements without parentheses: print "Hello, world!" I did a find and replace to get this: verboseprint "Hello, world!" But now, I want to do a find and replace to get this: verboseprint ("Hello, world!") This involves the following steps: Finding strings based on a regex (which I know emacs can do) Having the replacement string take a portion of the original string (which I'm not sure if emacs can do) So in pseudocode, when I do my "find", I'd be searching for: "verboseprint" + (characters until newline) and I'd replace it with "verboseprint(" + (characters until newline) + ")" Is this even possible in emacs? Any help would be appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire