Alright, let me start off by saying that what you're trying has become the new traveling salesman problem. But, I wanted to reference this post in which the post below the accepted answer states you can in fact parse HTML with regular expressions - you just don't want to. Please read it because it will help you understand the hurdles.
Now, on to your specific problem.
Let's say you had some HTMl like this:
<html>
<head>
</head>
<body>
<span style="line-height: 14px; font-family: Arial, Helvetica, sans; font-size: 11px;">Some text in the span</span>
</body>
</html>
And you wanted to find and replace the line-height
, you might write a RegEx like this:
line-height.+?;
And I think you can extrapolate the rest from that RegEx. However, the problem is that you're assuming that there is a ;
ending that statement always - and with CSS I'm not sure you can assume that, so that's why everybody tells you it can't be done with regular expressions. But follow along with me for a minute. Now, in C# you might write something like this (documented here):
var newString = RegEx.Replace(htmlString, "(line-height:)(.+?)(;)", "$1 $3");
The $1
and $3
will preserve the first and third captured expressions.