我在使用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