求正则

jrl5365 2009-04-08 04:05:39
<input id="txtShoolName" type="text" style="width: 150px;" class="input" />
<select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>
.....很多个HTML

1.等不同的HTML,我现在能得到<input id="txtShoolName" type="text" style="width: 150px;" class="input" />或<select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>的HTML
2.每个控件的HTML的ID是不一样的!所以这个ID要动态的提取


要求把id对应的加上一个i变量,这个i我已定
如:
<input id="txtShoolName2" type="text" style="width: 150px;" class="input" />
<select name="DropDegree2" id="DropDegree" class="input" style="width: 150px;">
</select>
...全文
142 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
LemIST 2009-04-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jrl5365 的回复:]
引用 7 楼 LemIST 的回复:
引用 6 楼 jrl5365 的回复:
引用 5 楼 LemIST 的回复:
引用 1 楼 jrl5365 的回复:
我现在是这样打算的!可后面不知道咋写
var str=' <select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写

str=str.replace(/id=[\w]*/,'id="' + i + '"');


要把原来的ID拿来后面再加个数字 …
[/Quote]
此版不是C#么?
jrl5365 2009-04-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 LemIST 的回复:]
引用 6 楼 jrl5365 的回复:
引用 5 楼 LemIST 的回复:
引用 1 楼 jrl5365 的回复:
我现在是这样打算的!可后面不知道咋写
var str=' <select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写

str=str.replace(/id=[\w]*/,'id="' + i + '"');


要把原来的ID拿来后面再加个数字

in C#


{

Rege…
[/Quote]

请用JS,谢谢!
jrl5365 2009-04-09
  • 打赏
  • 举报
回复


是C#版,但这个地方想用js来实现!
LemIST 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 jrl5365 的回复:]
引用 5 楼 LemIST 的回复:
引用 1 楼 jrl5365 的回复:
我现在是这样打算的!可后面不知道咋写
var str=' <select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写

str=str.replace(/id=[\w]*/,'id="' + i + '"');


要把原来的ID拿来后面再加个数字
[/Quote]
in C#


{

Regex reg = new Regex("(/id=[\w]*/");

str = Regex.Replace(str, MatchE);
}

public string MatchE(Match mat)
{
return mat.Groups[1].Value + 数字;
}
jrl5365 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 LemIST 的回复:]
引用 1 楼 jrl5365 的回复:
我现在是这样打算的!可后面不知道咋写
var str=' <select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写

str=str.replace(/id=[\w]*/,'id="' + i + '"');
[/Quote]

要把原来的ID拿来后面再加个数字
LemIST 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jrl5365 的回复:]
我现在是这样打算的!可后面不知道咋写
var str=' <select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写
[/Quote]
str=str.replace(/id=[\w]*/,'id="' + i + '"');
jrl5365 2009-04-08
  • 打赏
  • 举报
回复


高手们,帮帮我呀
liuhangbing 2009-04-08
  • 打赏
  • 举报
回复
^id/=/"[a-zA-Z]+/"$
jrl5365 2009-04-08
  • 打赏
  • 举报
回复
jrl5365 2009-04-08
  • 打赏
  • 举报
回复
我现在是这样打算的!可后面不知道咋写
var str='<select name="DropDegree" id="DropDegree" class="input" style="width: 150px;">
</select>';
str=str.replace(/id=[\w]*/,***i);
***这个地方不知道咋写

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧