如何用正则匹配a标签的属性
答案:2 悬赏:0 手机版
解决时间 2021-04-14 21:35
- 提问者网友:温柔港
- 2021-04-14 10:29
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-04-14 10:54
C#代码,需要using System.Text.RegularExpressions; string linkA = string.Empty;
string textA = string.Empty; string m="qsa"; string pattern = @"\(?.+?)\"; Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rr.Matches(m); foreach (Match match in matches)
{
linkA = match.Groups["linkA"].Value;
textA = match.Groups["textA"].Value;
}
string textA = string.Empty; string m="qsa"; string pattern = @"\(?.+?)\"; Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rr.Matches(m); foreach (Match match in matches)
{
linkA = match.Groups["linkA"].Value;
textA = match.Groups["textA"].Value;
}
全部回答
- 1楼网友:老鼠爱大米
- 2021-04-14 12:08
c#代码,需要using system.text.regularexpressions;
string linka = string.empty; string texta = string.empty;
string m="<a href='dd.asp'>qsa</a>";
string pattern = @"\<a.*?href='(?<linka>.+?)'.*\>(?<texta>.+?)\</a\>";
regex rr = new regex(pattern, regexoptions.ignorecase); matchcollection matches = rr.matches(m);
foreach (match match in matches) { linka = match.groups["linka"].value; texta = match.groups["texta"].value; }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯