2

htmlの詳細を含む列があり、各列内にhtmlにさまざまなhttpリンクが含まれています。各列のすべてのhttpリンクを見つける必要があります。

例:列1行1

html 
... 
a href = http://www.column1.com....... 
img src=http://www.pic1.com/images/im.jpg...
...
/html

列1行2

html 
...
a href = http://www.column2.com.......  
img src="http://www.pic2.com/images/im.jpg".... 
/html

結果として、次のリストを取得する必要があります。

  • 最初の列のlink1最初の列のhrefドメインの1imgリンク
  • 2番目の列のlink22番目の列のhrefドメインの2img2リンク

私は何をすべきか全く手がかりがなく、SQLを使うのが苦手なので、誰かがこれを見つけるのを手伝ってもらえますか?

4

1 に答える 1

1

charindexのインデックスを検索するために使用できます。http://次に、URLの末尾を検索する必要があります(データ、スペース、または "によって異なります)。

正規表現の検索を実装して、CLRスカラー関数を作成することもできます

using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public class CLR
{
    [SqlFunction(FillRowMethodName = "FillRow")]
    public static IEnumerable RegexMatch(string pattern, string text)
    {
        var r = new Regex(pattern);
        return r.Matches(text);
    }

    public static void FillRow(Object obj, out SqlInt32 index, out SqlString match)
    {
        var m = (Match)obj;
        index = new SqlInt32(m.Groups[0].Index + 1);
        match = new SqlString(m.Groups[0].Value);
    }
}

次に、このクラスライブラリからSQLServer上にアセンブリを作成する必要があります

create assembly CLR from 'C:\CLR.dll' with permission_set = safe

次に、関数を作成できます

create function RegexMatch(@pattern nvarchar(4000), @text nvarchar(4000))
returns table ([index] int, match nvarchar(4000))
as external name CLR.CLR.RegexMatch
于 2012-10-24T13:30:01.897 に答える