如何提取星号之间的文本?
SELECT substring('QUITAR1 *W01 - 123456/9* QUITAR2 ' from '%#"*_*#"_' for '#')
我需要通过以下方式检索文本:W01 - 123456/9
PostgreSQL 9.5.-
最佳答案
如果你想使用 substring with regular ,带星号到方括号:
t=# SELECT substring('QUITAR1 *W01 - 123456/9* QUITAR2 ' from '%#"[*]%[*]#"%' for '#');
substring
------------------
*W01 - 123456/9*
(1 row)
所以得到你想要的:
t=# SELECT replace(substring('QUITAR1 *W01 - 123456/9* QUITAR2 ' from '%#"[*]%[*]#"%' for '#'),'*','');
replace
----------------
W01 - 123456/9
(1 row)
我正在使用替换,因为文本中有星号可能会破坏面具
关于regex - 如何提取 Postgresql 中星号之间的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46429384/