Regular expression for multiple lines replace

Find, replace, find in files, replace in files, regular expressions

Regular expression for multiple lines replace

Postby o_t_a » Fri Jan 28, 2005 8:38 am

Looking for regular expression (I'd appreciate both UE & Unix style) which will take whole block of code and will insert some string before and after.
Example:
Code: Select all
body
  {
  background-color: #fff;
  color: #000;
  margin: 0;
  padding: 0;
  text-align: justify;
  }

when using replace dialog for eg. line with margin and padding selection it will produce this:
Code: Select all
body
  {
  background-color: #fff;
  color: #000;
/*
  margin: 0;
  padding: 0;
*/
  text-align: justify;
  }


Thanks for any help
User avatar
o_t_a
Newbie
 
Posts: 1
Joined: Fri Jan 28, 2005 12:00 am

Re: Regular expression for multiple lines replace

Postby Mofi » Sun Jun 25, 2006 11:09 am

Can be done without a regular expression. After selecting the lines

Code: Select all
  margin: 0;
  padding: 0;


press Ctrl+R to open the replace dialog and enter in the find field ^s and in the replace field /*^p^s*/^p (for DOS terminated files or Unix/Mac files which are temporarily converted to DOS on load).

If you want to use the "MakeBlockCmt" replace often, use a macro with a hot key. Here is the macro code:

IfSel
IfExtIs "css"
Find "^s"
Replace "/*^p^s*/^p"
ExitMacro
EndIf
IfExtIs "html"
Find "^s"
Replace "<!-- ^s -->"
ExitMacro
EndIf
IfExtIs "htm"
Find "^s"
Replace "<!-- ^s -->"
ExitMacro
EndIf
EndIf


See also Usage of ^c and ^s in search and replace.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4058
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Find/Replace/Regular Expressions