日期:2014-05-17  浏览次数:20869 次

如何使用C#正则替换一段字符串
源字符串为:
<img class="SIGN" title="签章控件:sfsdfsdfsdf" border="0" name="DATA_10" alt="" align="absMiddle" value="sfsdfsdfsdf" 

sign_type="1,1," style="cursor: hand" src="/module/html_editor/editor/images/sign.gif" />&#160

以class="SIGN"为特征标记,遇到class="SIGN"的img标签就替换

最终将上面的源字符串替换为
<div class='websign' id=SIGN_POS_DATA_10 sign_type="1,1,">&nbsp;<input type=button value=盖章 

onclick="addSeal('DATA_10')">
<input type=button value=手写 onclick="handWrite('DATA_10')">
<input type=hidden name=DATA_10 value=''>
</div>

------解决方案--------------------
C# code
(?is)<img.*?class="sign"[^>]*>

------解决方案--------------------
<img\s*class="SIGN".*?name="([^"]*)"[^>]*>
------解决方案--------------------
C# code

            string input = @"<img class=""SIGN"" title=""签章控件:sfsdfsdfsdf"" border=""0"" name=""DATA_10"" alt="""" align=""absMiddle"" value=""sfsdfsdfsdf""  

sign_type=""1,1,"" style=""cursor: hand"" src=""/module/html_editor/editor/images/sign.gif"" />";
            Console.WriteLine(new Regex(@"(?is)<img.*?class=""sign""[^>]*>").Replace(input, @"<div class='websign' id=SIGN_POS_DATA_10 sign_type=""1,1,"">&nbsp;<input type=button value=盖章  

onclick=""addSeal('DATA_10')"">
<input type=button value=手写 onclick=""handWrite('DATA_10')"">
<input type=hidden name=DATA_10 value=''>
</div>"));

------解决方案--------------------
探讨

原来是
<img class="SIGN" title="签章控件:sfsdfsdfsdf" border="0" name="DATA_10" alt="" align="absMiddle" value="sfsdfsdfsdf" sign_type="1,1," style="cursor: hand" src="/module/html_editor/editor/images/sig……

------解决方案--------------------
我也想知道答案
------解决方案--------------------
稍微有点理解了,lz你说清那些数据是关联对应的啊!