Выбор всех свойств CSS с помощью скобок, чтобы стереть их

469
MauF

Как искать в файле CSS и с помощью Komodo Edit все внутри, включая скобки из каждого правила стиля CSS.

Мне нужно закончить со списком классов CSS и идентификаторов, стирающих все свойства из очень большого файла CSS.

Мне нужно включить это:

.template{ color: #FFF; } .template1{ color:red; } 

в это:

.template .template1 

Заранее спасибо.

0

2 ответа на вопрос

2
DiegoDD

you could use a regular expression to find every appearance of things between '{' and '}', and then replace them with "nothing". Note that I don't know Komodo Edit, but I'm guessing it is capable of using regular expressions to search / replace text. Sou you'll have to find out how.

the expression could be like this:

{[\w\s:;#]*}

If you don't know regular expressions, here it is a short explanation:

  • { and } match the { and }
  • [] is the group of characters you will look into the brackets, and here goes whatever you need to select.
  • \w matches leters and numbers, and the underscore
  • \s matches white spaces (spaces, tabs, etc)
  • : ; # - directly matches those symbols

just add any other symbols that you may find between the { }, I may forgot some of them.

However, I highly recommend learning regular expressions, they are a powerful tool to achieve exactly what you need.

A nice playground for regexs can be found here, and over here I've put you the regex I suggest for you to play around with it.

One last word: If you need more help with regular expressions, you could go to stackoverflow instead of here. (perhaps they'll even migrate your post, but I'm answering you here).

good luck!

Спасибо Диего. Ваш ответ указал мне правильное направление, но я все еще не могу выбрать КАЖДЫЙ отдельный блок текста в фигурных скобках. Некоторые выбраны, некоторые нет. Я думаю, мне нужно быть более конкретным (или нет, мне придется проверить). MauF 11 лет назад 0
0
MauF

Я немного повозился с этим шаблоном RegEx:

\{[^\}]*\} 

Я могу выбрать все, что мне нужно, в том числе такие строки, как:

{ background:url("../img/mas.png") no-repeat scroll center top transparent;height:19px;padding:0;position:relative;width:20px;z-index:98; }