开发者

commenting out multiple lines of code with regular expressions

开发者 https://www.devze.com 2023-01-31 13:01 出处:网络
I want to find every instance of a background image in a CSS document and comment 开发者_开发技巧it out:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消