如何提取 Postgresql 中星号之间的文本?

How can I extract the text between asterisks in Postgresql?

如何提取星号之间的文字?

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)

我正在使用替换,因为文本中有星号可能会破坏面具