读书人

求一正则表达式 提取lt;input 中id属性值

发布时间: 2012-01-06 22:55:18 作者: rapoo

求一正则表达式 提取<input 中id属性值>
<table border= "1 ">
<tr>
<td>
姓名 </td>
<td>
<input type= "text " id= "姓名_Text_Name " /> </td>
<td>
年龄 </td>
<td>
<input type= "text " id= "年龄_Text_Age " /> </td>
</tr>
</table>

我需要的是把 <input type= "text " id= "姓名_Text_Name " /> 替换为 姓名_Text_Name 和 <input type= "text " id= "年龄_Text_Age " /> 替换为 年龄_Text_Age
但 input中的属性个数不固定,能给出代码段最好不过了。谢谢


[解决办法]
上面的例子中
<input type= " "text " " id=姓名_Text_Name /> </td>
就是没有引号的,我测试过,没问题的

注意str = Regex.Replace(str, " <input.*?id=([ '\ "]?)([^ '\ "\\s> ]+)\\1[^> ]*> ", "$2 ", RegexOptions.IgnoreCase);
后面是 "$2 ",不是 "$1 "了,都改过来才可以

读书人网 >C#

热点推荐