c# - string replace with exception on certain strings -
i have line of code i'm using prepare css file:
theminifiedcss = theminifiedcss.replace("white", "#fff");
the problem in css, have declaration:
.someclass{white-space:pre-wrap;}
how change .replace
statement replace white
#fff
leave white-space
alone?
thanks.
note, know can add theminifiedcss = theminifiedcss.replace("#fff-space", "white-space");
i'm looking cleaner.
people keep trying write rules things appear before or after "white"
, when think what's desired "white"
own token , not part of selector.
regex.replace(theminifiedcss, @"(?<![-_a-za-z0-9#.])white(?![-_a-za-z0-9])", @"#fff");
a more complete rule implement entire rule identifier tokens in css, think 1 covers keywords.
here's trickier test case has been posted far:
.white> td { color: white;box-shadow: 0px 0px 3px white, inset 0px 0px 5px black; white-space:pre-wrap; } body { background: url('test.png'),white; }
even trickier, , not handled example, filenames.
body { background-color:white; background-image:url('almost white, not really.png'); }
to right, need full css parser.
Comments
Post a Comment