我在使用LinqToTwitter API的twitter API。我正在尝试格式化tweet文字。但是我有一个问题,更换和下面的正则表达式是我从Twitter替换和RegEx问题
@TheNational: ICYMI: Louvre be first museum in Asia to show a painting http://t.co/fmp http://t.c…
让我现在用下面的代码替换所有的URL链接,显示的字符串。
首先,我创建正则表达式来获取链接
private readonly Regex _parseUrls = new Regex("(?<Protocol>\\w+):\\/\\/(?<Domain>[\\[email protected]][\\w.:@]+)\\/?[\\w\\.?=%&=\\[email protected]/$,]*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
然后,我与它们匹配和替换如下
foreach (var urlMatch in _parseUrls.Matches(tweetText))
{
Match match = (Match)urlMatch;
tweetText = tweetText.Replace(match.Value, string.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", match.Value));
}
正则表达式按预期工作非常好,但现在取而代之的是给问题,因为在这两个环节字符串以http://t.co
开头,每次都替换第一次出现。
有人帮助我,我失踪了。
你解决了我的大问题非常感谢你 – Milind 2014-12-06 14:59:41