Regex to replace text between two strings c# -
i have following string :
<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>
and using regex
replace above string empty in between 2 tags <span style="display:none"> * </span>
. using code below:
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>", "");
but above replaces string first <span style=\"display:none\">
till end.i have tried different combinations. advise.
use .*?
instead , lazy , .*
greedy.
the greedy regex eats after match gets. while .*? reluctant match , match till condition satisfied
Comments
Post a Comment