繁体   English   中英

PostgreSQL:在双括号之间获取字符串

[英]PostgreSQL: Getting Strings between double Brackets

我是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. 

现在,我要提取方括号[[]]之间的每个String。 但是我该怎么做呢? 甚至没有插件也有可能吗?

我用LIKE尝试了不同的版本,但没有产生任何结果,例如:

SELECT * FROM book WHERE page LIKE '[[%]]';
SELECT * FROM book WHERE page LIKE '[[teenager]]';
...

我也使用了regex,但是我只得到了整个数据集,而不是括号之间的String:

SELECT * from book where page ~ '[^[[]+(?=\]])';

我的问题有解决方案吗? 帮助将不胜感激!

使用regexp_matches函数:

select regexp_matches(page,'[^[[]+(?=\]])','g') from book

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM