R – Help with an Emacs Regular Expression

emacsregex

I have statements like this all over my code:

LogWrite (String1,
          String2,
          L"=======format string======",
          ...
          );

I want to change each of these to:

LogWrite (String1,
          String2,
          L"format string",
          ...
          );

I'm trying to write the regexp required to do this using the Emacs function query-replace-regexp, but not much success yet. Help please!


UPDATE:
1) In case it is not clear, this question is emacs specific.

2) I would like to match the entire code chunk starting from Log… ending at );

3) I used the following reg-exp to match the code chunk:

L.*\n.*\n.*==.*;

I used re-builder to match this regexp. the \n is used because I found that otherwise emacs would stop matching at the new line. The problem is that I don't know how to select the format string and save it to use it in the replace regexp – hence the ==.* part in the regexp. That needs to be modified to save the format string.

Best Answer

If you don't have multiple (or escaped) double quotes in those format string lines, you can

//replace

L"=+(.*)=+"

//with 

L"\1"

Update: Removed the lazy quantifier (thanks @tim). Make sure that the regex is not multiline; the greedy * will lead to pretty bad results if . matches new lines