1.一个源字符串:
<a href=aa.asp>aaaa</a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒1</font></nobr></a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>
2.源字符的内容可能是变化的,但我们已知道此字符串有标题为"文新传媒2"的超链接。
3.我想得到字符串:
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>4.
我用:[^>]*(?<title><a.*?文新传媒2.*?a>) 试了,但没有取值成功。请各位高手帮助解决下此问题。谢啦!
<a href=aa.asp>aaaa</a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒1</font></nobr></a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>
2.源字符的内容可能是变化的,但我们已知道此字符串有标题为"文新传媒2"的超链接。
3.我想得到字符串:
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>4.
我用:[^>]*(?<title><a.*?文新传媒2.*?a>) 试了,但没有取值成功。请各位高手帮助解决下此问题。谢啦!
Match m = reg.Match("sdfas><a href=\"http://www.news365.com.cn/yw/t20050822_621630.htm\" target=_blank><nobr><font size=2>文新传媒2</font></nobr></a><dsfsadfla>adf</a>");Console.WriteLine(m.Value);
你在源字符串:<a href=aa.asp>aaaa</a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒1</font></nobr></a>
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>
中用你的:string p = @"<a\s*.*文新传媒2.*?</a>";
我试了,匹配出来的结果不是:
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>
<nobr><font size=2>文新传媒2</font></nobr></a>
@"<a[^>]*>[\s\S]{1,30}?文新传媒2[\s\S]*?</a>",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
我想部下:
"<a[^>]*>[\s\S]{1,30}?文新传媒2[\s\S]*?</a>", 中的{1,30} 能讲下是什么意思吗,为这样写呢?
用你的表达式在匹配:
类似于这样的字符串时:
<a href="http://www.news365.com.cn/yw/t20050822_621630.htm" target=_blank>文新传媒3</a>
就无法匹配出结果来。
除非你给出更多的例子,再进行针对的修改
问一个另外的问题:
我有个页面文件如aa.htm 有500k, 我想把其中的字符串:<a href=1.htm>文新传媒</a>
替换为:hello<a href=1.htm>文新传媒</a>
用什么方法速度快一点。我用的方法是:
Regex regex2 = new Regex(enTitle,RegexOptions.IgnoreCase | RegexOptions.Compiled);
sHtml=regex2.Replace(sHtml,"${title}工作组");
运行程序后功能可以实现,但我发现在匹配过程中cpu使用率为100%,持续时间为2秒才运算出结果,
这样的速度太慢了!! 而且cup怎么为100%呢?!!老兄可以好一点的方法?谢谢!
你的enTitle是什么?怎么读的文件?