日期:2014-05-18  浏览次数:20825 次

求一正则表达式 提取<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 "了,都改过来才可以