SELECT (regexp_matches('Euroschinus Hoff+300'::text, E'(Euroschinus Hoff[\+])([0- 9]+)'::text)::text[])[1]::text as counter
select array_scientificname from simple_cal where array_scientificname ~ 'Semecarpus'
但是,如果有一些括號,沒關係,其中的文字,既沒有工作
SELECT (regexp_matches('Euroschinus (testing) Hoff+300'::text, E'(Euroschinus (testing) Hoff[\+])([0-9]+)'::text)::text[])[1]::text as counter
select array_scientificname from simple_cal where array_scientificname ~ 'Semecarpus(test)'
我只是想獲取文本。沒有爲()定義的模式,可以在文本的任何地方。
我注意到在括號前使用\來做它的竅門(見下文),但這根本不實用。我想我應該包括的地方,()被允許在字符串中...
SELECT (regexp_matches('Euroschinus (testing) Hoff+300'::text, E'(Euroschinus jaffrei \\(testing\\) Hoff[\+])([0-9]+)'::text)::text[])[1]::text as counter
1'jaffrei'字損害你的正則表達式 2.我不明白 - 你想提取它之前的數字或文字? '計數器'表示第一個,'[1]'表示第二個。 – LisMorski 2012-07-19 12:11:45
這個問題目前還不清楚。請添加一個字符串示例以及您想要從中獲得的內容。 – 2012-07-19 13:05:09