我有以下字符串:
<span><style>
.G9cT{display:none}
.Q-Bv{display:inline}
</style><span class="G9cT">74</span><span style="display:none">100</span><span class="G9cT">100</span><div style="display:none">100</div><span style="display:none">122</span><span class="G9cT">122</span><div style="display:none">122</div><span style="display:none">178</span><span class="G9cT">178</span><span class="165">189</span><span class="G9cT">202</span><div style="display:none">202</div><span style="display:none">214</span><span class="G9cT">214</span><div style="display:none">214</div><span style="display:none">230</span><div style="display:none">230</div><span class="Q-Bv">.</span><span style="display:none">53</span><span class="G9cT">53</span><span class="G9cT">68</span><div style="display:none">68</div><span style="display:none">81</span><span class="G9cT">81</span><div style="display:none">81</div><span style="display: inline">112</span><span style="display:none">124</span><span class="G9cT">124</span><div style="display:none">127</div><span style="display:none">129</span><span class="G9cT">129</span><span></span><span class="G9cT">151</span><div style="display:none">155</div><span style="display:none">194</span><div style="display:none">194</div><span style="display:none">233</span><span class="G9cT">233</span><span></span><span class="G9cT">234</span><span class="Q-Bv">.</span><span></span><div style="display:none">61</div>88<div style="display:none">98</div><span style="display:none">105</span><span class="G9cT">105</span><div style="display:none">105</div><div style="display:none">117</div><span style="display:none">197</span><span class="G9cT">197</span><div style="display:none">197</div><span style="display: inline">.</span><span class="Q-Bv">65</span><span style="display:none">147</span><div style="display:none">147</div></span>
我正在使用Regex
在两个标记<span style="display:none"> * </span>
之间用空格替换上面的字符串。我使用下面的代码:
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("<span style=\"display:none\">(.*)</span>");
var v = regex.Match(txxt);
string output = System.Text.RegularExpressions.Regex.Replace(txxt, "<span style=\"display:none\">(.*)</span>", "");
但是上面的代码从第一个<span style=\"display:none\">
替换到结尾。我尝试了不同的组合。任何建议。
答案 0 :(得分:5)
使用.*?
代替,懒惰,.*
贪婪。