V
V
Vitaly Mironov2018-05-03 18:42:20
css
Vitaly Mironov, 2018-05-03 18:42:20

How to remove a rule in css regex?

Good day. Can you please tell me how to remove unnamed rules in css with a regular expression?
Example:

{
  color: red;
}

I wrote a regular expression
/((\n|\s{2,3})\{)(.+?)\}/is
. It works, but it also removes such rules.
a
{
color: red
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sergey, 2018-05-03
@nor1m

https://regex101.com/r/OFX59Z/7
Here you can change the number of hyphens after the defining selector by duplicating [\w)] with \s added inside the "look-back" group (?<!). And in [\w)] add some more characters to prevent deletion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question