Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text - Find any text between two defined characters

I am working on removing all of the css attributes in a stylesheet without removing the selector.

For example I want to take this:

.format-chat .chat .chat-timestamp {
    color: #722d19;
    float: right;
    font-size: 12px;
    font-weight: normal;
    margin: 5px 10px 0;
}

And turn it into this:

.format-chat .chat .chat-timestamp {
}

Since I am working with several thousand lines of CSS it would be nice to do somthing like this in one action, with a simple find and replace. In this case I want to find all text between curly brackets { }.

like image 225
SmashBrando Avatar asked Oct 02 '13 17:10

SmashBrando


People also ask

How do I find a character in a string in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).

How do I find and replace in Sublime Text?

Or, if you want to find and replace text in a number of files at once, press Command + Shift + F or Control + Shift + H to open Sublime Text's Find in Files tool that can search and replace across as many files as you have open or select from its menu.

How do I use regular expressions in Sublime Text?

To use regular expressions in Sublime Text, first activate them in the corresponding search panel by clicking on the available buttons or using keyboard shortcuts. If you don't activate regular expressions before performing a search, the search terms will be interpreted literally.


1 Answers

You can simply use the following regex to find everything inside { and }:

\{[^}]*\}

and replace with literal {}.

like image 154
Ibrahim Najjar Avatar answered Oct 23 '22 08:10

Ibrahim Najjar