Answer the question
In order to leave comments, you need to log in
Removing css selectors?
Good day comrades.
How to remove css selector with regex?
For example, cut the selector a
.a[title], a .a[attr$='value']{
color: red;
}
a[title]{
color: red;
}
a[attr$='value']{
visibility: hidden;
}
a[attr='value']{
visibility: hidden;
}
a[href='#home'], div{
vertical-align: middle;
}
.a a[attr ~= 'value']{
color: red;
}
.a a[attr$='value']{
color: red;
}
a ~ b, a[title]{
color:red;
}
a ~ b, .a[attr$="value"]{
color:red;
}
.a[href="#"], div{
float: left;
}
.a[title], .a[attr$='value']{
color: red;
}
div{
vertical-align: middle;
}
.a{
color: red;
}
.a{
color: red;
}
b, .a[attr$="value"]{
color:red;
}
b{
color:red;
}
div{
float: left;
}
// удаление селекторов со свойствами
foreach ($array_unused as $key => $value) {
$pattern = trim( preg_quote($value) );
$ready_css = preg_replace('/'.$pattern.'[^}]+\}/is','', $ready_css);
}
// удаление просто селекторов
foreach ($array_unused_comma as $key => $value) {
$pattern = trim( preg_quote($value) );
// если теги
if(! preg_match('/[+>~.#,]/i', $pattern) ){
if ( preg_match('/(\s,|,|,\s)'.$pattern.'/', $ready_css) ){
$ready_css = preg_replace('/(\s,|,|,\s)'.$pattern.'/','', $ready_css);
} else if ( preg_match('/'.$pattern.'(\s,|,|,\s)/', $ready_css) ){
$ready_css = preg_replace('/'.$pattern.'(\s,|,|,\s)/','', $ready_css);
}
$ready_css = preg_replace('/('.$pattern.'{|'.$pattern.'\s+{)/i','{', $ready_css);
}
// если классы и айдишники
else{
if ( preg_match('/(\s,|,|,\s)'.$pattern.'/', $ready_css) ){
$ready_css = preg_replace('/(\s,|,|,\s)'.$pattern.'/','', $ready_css);
} else if ( preg_match('/'.$pattern.'(\s,|,|,\s)/', $ready_css) ){
$ready_css = preg_replace('/'.$pattern.'(\s,|,|,\s)/','', $ready_css);
} else {
$ready_css = preg_replace('/'.$pattern.'/','', $ready_css);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question