2

我有一个包含大量旧 phpBB 数据的数据库,其中包含带有以下文本的帖子:

[b:522f1e2c15]bold[/b:522f1e2c15]
[i:522f1e2c15]italic[/i:522f1e2c15]
[u:522f1e2c15]underline[/u:522f1e2c15]
[img:522f1e2c15]http://www.mysite.com/myimage.jpg[/img:522f1e2c15]
[quote:522f1e2c15="Mark"]quoted text by Mark[/quote:522f1e2c15]

我们需要将此数据迁移到新系统,但作为该过程的一部分,我们需要替换出现在各种标签中的唯一 ID,因此上述内容将变为:

[b]bold[/b]
[i]italic[/i]
[u]underline[/u]
[img]http://www.mysite.com/myimage.jpg[/img]
[quote=Mark]quoted text by Mark[/quote]

我希望一些 SQL RegEx 大师可以展示如何做到这一点?

4

1 回答 1

2

只是一个可能的解决方案。使用正则表达式匹配组,然后排除唯一 id 组。

string pattern = @"(\[b)(:\w+)(\]\w+\[\/b)(:\w+)(\])";
string input = "[b:522f1e2c15]bold[/b:522f1e2c15]";
Match m = Regex.Match(input,pattern);
Console.WriteLine("{0}{1}{2}", m.Groups[1].Value, m.Groups[3].Value, m.Groups[5].Value);
于 2012-06-14T13:29:56.617 回答