【发布时间】:2014-03-03 14:29:23
【问题描述】:
我是 PostgreSQL 的新手,并决定尝试一下。因此,我想从标记文本中提取字符串,但没有得到我想要的结果。
为此,我有一个名为 book 的简单表和一个名为 page 的文本数据类型的列。
数据看起来像这样:
Simon the Sorcerer is a [[teenager]] transported into a fantasy world as a
[[Sorcerer (person)|sorcerer]] dressed in a cloak and [[pointy hat]]; his
cloak and hat are purple in the first game, but change to red for the rest
of the series (aside from possible magical colour changes in the third game).
He must use his logic and magical skills to solve puzzles as he progresses
through the games.
现在我想提取括号 [[ ]] 之间的每个字符串。但是我该如何正确地做到这一点?还是没有插件也能做到?
我用 LIKE 尝试了不同的版本,但没有产生任何结果,例如:
SELECT * FROM book WHERE page LIKE '[[%]]';
SELECT * FROM book WHERE page LIKE '[[teenager]]';
...
我也玩了一点正则表达式,但我只取回了整个数据集,而不是括号之间的字符串:
SELECT * from book where page ~ '[^[[]+(?=\]])';
我的问题有解决方案吗?非常感谢您的帮助!
【问题讨论】:
标签: sql regex postgresql search pattern-matching