Javascript regular expression needed
Here is开发者_高级运维 the format of the css I'm trying to edit using jquery.
/*8d*/ .class{color:#444444;}
/*5d*/ .class{background-color:#444444;}
/*3f*/ .class{color:#444444;}
/*9d*/ .class{color:#444444;}
I want to replace several entire lines within using Regular Expressions. For example, How do I select line 5d the replace with "/*5d*/ .new{border:#676767;}" so the end result is;
/*8d*/ .class{color:#444444;}
/*5d*/ .new{border:#676767;}
/*3f*/ .class{color:#444444;}
/*9d*/ .class{color:#444444;}
Thanks.
If you want to replace the 5d
line, search for:
\/\*(5d)\*\/.*
and replace the match with
/*\1*/ .new{border:#676767;}
Note that \1
is a backreference to 5d
.
could you use toggleClass or addClass / removeClass?
css.replace(/\/\*5d\*\/.*/, '/*5d*/.new{border:#676767;}');
Of course if you have your css in that format, with one rule on one line. If you have it on multiple line you'll have to use this:
css.replace(/\/\*5d\*\/{.*?}/s, '/*5d*/.new{border:#676767;}');
But if you have comments inside you rule things get more complicated and I don't think regex is enough.
精彩评论