4

データベースには、常にタグを持つフィールドがあります。そしてまたたくさんのテキスト..

例えば:

Hey there.. whats up?
<img src="http://cdn.theatlantic.com/static/infocus/ngpc112812/s_n01_nursingm.jpg" alt="" />
.. and this is my photo!..

私は何の間だけを取得する必要があります

ソース

私は試した :

public string LinkPicCorrect(string path)
{
    //string input = "[img]http://imagesource.com[/img]";
    string pattern = @"\<img>([^\]]+)\\/>";
    string result = Regex.Replace(path, pattern, m =>
    {
        var url = m.Groups[1].Value;
        // do something with url here
        // return the replace value
        return @"<img src=""" + url + @""" border=""0"" />";
    },
        RegexOptions.IgnoreCase);

    result = "<img src='" + result + "'/>";

    return result;
}

しかし、解析エラーがあります:

例外の詳細: System.ArgumentException: "\([^]]+)\/>" の解析 - 未定義のグループ名 img への参照。

私のコードが正しいパスかどうかはわかりません...

4

2 に答える 2

1

この正規表現パターンを試すことができます:-

string pattern= Regex.Match(path, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
于 2013-08-20T08:36:47.050 に答える