0
<a href="http://www.try.com"><strong>Try link word</strong></a>  

你好。我怎样才能把这个字符串的一部分

http://www.try.com尝试链接词

使用 c# 4.0 正则表达式?

我尝试了这个,但没有奏效;

var expression = @"<a href=""(.*?)""><strong>(.*?)</strong>";
                        Match m = Regex.Match(text, expression);
                        while (m.Success)
                        {
                            Response.Write("Match: " + m.Groups[0] + " <br> Area code: " + m.Groups[1] +"<br><hr><br>");
                            m = m.NextMatch();
                        }
4

1 回答 1

2

我尝试了您的代码并得到了这个:

Match: <a href="http://www.try.com"><strong>Try link word</strong> <br> Area code: http://www.try.com<br><hr><br>

(psst,下次你有一些“不起作用”的代码时,把你在你的问题中得到的,以及你期望的)。

改变:

Response.Write("Match: " + m.Groups[0] + " <br> Area code: " + m.Groups[1] +"<br><hr><br>");

Response.Write("Match: " + m.Groups[1] + " <br> Area code: " + m.Groups[2] +"<br><hr><br>");

给我这个:

Match: http://www.try.com <br> Area code: Try link word<br><hr><br>

那是你想要的吗?

于 2013-03-08T15:06:03.340 回答