Reputation: 767
I have a long CSS file and want to clean it up by removing the different lines and copying them into the appropriate Scss file:
_layout.scss, _colorscheme.scss, _type.scss
The regex from the following thread is a great approach: How do you delete lines with certain keywords in VScode
However, class names are also matched, see example:
Regex:
^.*(radius|width|box-shadow|padding|margin|display:|height:).*\n
Code-Example:
.margin-text-class {
margin: 1rem;
color: #fff;
}
For the sake of completeness, here are my current regex to separate.
Regex for fonts:
^.*(font|line-height|letter-spacing).*\n
Regex for colors:
^.*(color:|background-color|rgba).*\n
I found a regex that selects everything within the brackets: Currently only when everything is in one line.
(?<=\{)(.*?)(?=\})
Does anyone have any idea how to combine these?
Upvotes: 0
Views: 110
Reputation: 163362
Reading the posted answer, if you want to get all the lines after the {
without matching }
until the first occurrence of margin, you might also use a negated character class matching any char except }
\{[^\r}]+?\bmargin\b.*\r?\n
If margin can only be at the next line, you can match a newline after {
and then match margin in the next line making sure the line does not contain }
\{\r?\n[^\r\n}]*\bmargin\b[^\r\n}]*\r?\n
Note that these patterns match a format as in the example data, and do not take any nesting into account.
Upvotes: 1
Reputation: 767
Thank you @Thefourthbird, your regex unfortunately selected the whole block, but I only needed the corresponding line. But the code helped me a lot because I was able to adapt it with it.
If someone else needs it, example for margin:
(?:\{)(?:\r?\n(?!\s*\}\s*\}).*)(^.*)(?=margin)(.*\n)
I use the regex to search and replace it with {
Upvotes: 0