postgresql:regexp_split_to_table - 如何通过分隔符拆分文本

时间:2015-12-15 17:15:38

标签: regex postgresql regexp-replace

我需要通过分隔符'<=''=>'将文本拆分为表格,例如

select regexp_split_to_table('kik plz <= p1 => and <= p2 => too. A say <=p1 =>','regexp');

结果必须是:

table:
--------------
1 | 'kik plz '
2 | '<= p1 =>'
3 | ' and '
4 | <= p2 =>
5 | ' too. A say '
6 | '<=p1 =>'

我认为答案是位置模式,但我的技能还不够。

select regexp_split_to_table('kik plz <= p1 => and <= p2 => too. A say <=p1 =>', '((\s)(?=<=))|((\s)(?!=>))') 

这会返回错误的结果。

1 个答案:

答案 0 :(得分:1)

select regexp_split_to_table(
    replace(
        replace('kik plz<= p1 =>and<= p2 =>too. A say <=p1 =>',  '<=',  E'\001<=')
    , '=>', E'=>\001')
, E'\001');