首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求一正则表达式 提取<input 中id属性值>该怎么解决

2012-01-06 
求一正则表达式 提取input 中id属性值tableborder 1 trtd姓名 /tdtdinputtype text id

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

热点排行