正規表現で問題が発生しています。
指定された文字列からすべての URL を取得したいのですが、.jpg、.css、.js、.gif などで終わる URL は取得したくありません。
これが私の ASP.NET C# コードです。
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
string result = client.DownloadString(strBasicUrl);
Regex MyRegex = new Regex("http(s)?://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
MatchCollection matches = MyRegex.Matches(result);
foreach (var item in matches)
{
litResult.Text += item.ToString() + "<br>";
}
}
この正規表現を変更したい....
strBasicUrl "http://www.Microsoft.com" をリクエストすると、 URLの下に結果はありません 例えば http://i.microsoft.com/en-us/homepage/shared/templates/components/hpSearch/images/searchSprite.ltr.gif http://i.microsoft.com/global/ImageStore/PublishingImages/Asset/Header/logo_skype.png
誰でも私を助けてくれますか?
前もって感謝します、 アミット・プラジャパティ