Replace contents of regexp_matches

时间:2015-10-19 15:47:09

标签: regex postgresql

I've got a regular expression that looks for certain types of numbers in a text string.

select regexp_matches
('+(+number: 921163 +number:(814541)) +(number: 770593 number: 772526 number: 771130) +numberer:9088054599082069', ' [0-9]\{6\} |[(][0-9]\{6\}[)]|:[0-9]{6} | [0-9]{6}', 'g');

That query successfully returns the numbers I'm interested in, albeit with some extra characters:

{" 921163 "}
{(814541)}
{" 770593 "}
{" 772526 "}
{" 771130"}

I'd like to then strip out all of the extra, non-numeric characters (spaces, parenthesis, etc.) from that result:

{921163}
{814541}
{770593}
{772526}
{771130}

I've tried wrapping my regexp_matches term with a regexp_replace, and regular old replace, but I haven't had any luck.

1 个答案:

答案 0 :(得分:0)

您需要的是

[[:<:]][0-9]{6}[[:>:]]

这是单词边界。它将删除匹配中的所有字符。