commenting out multiple lines of code with regular expressions
I want to find every instance of a background image in a CSS document and comment 开发者_开发技巧it out:
background: url('images/test.jpg') no-repeat top left;
becomes
background: /*url('images/test.jpg')*/ no-repeat top left;
I'm having trouble escaping the * and / (don't want to comment out the entire background selector).
couldn't you just put in the search box url('images/test.jpg')
and in the replace box: /*url('images/test.jpg')*/
(thus avoiding regular expressions at all)?
Setting the options 'search in:' to 'current document' and 'search for:' to 'source code', then hitting 'replace all'..
Search for:
(background)(.*)(url\('.*[^']'\))(.*)
Replace with:
$1$2/*$3*/$4
Something like this should work:
search for
background:(\s*url\s*\([^)]+\))
replace with
background:/*$1*/
You shouldn't have to escape the * and / in the replacement text
精彩评论