regexp_split_to_array,拆分'|'

时间:2014-12-13 13:16:13

标签: regex postgresql

我有一个字符串,包含名称/值对, eml:='clientName|img_0196.jpg||mime|||size|3195562||serverFileName|upload/548a5b35003bf.img_0196.jpg'

我需要拆分' |'。

我想获得{' clientName',' img_0196.jpg' ,,' mime' ,,,' size' ,. ..}。我的代码是:

    RAISE NOTICE 'eml: %', eml;
    fields := regexp_split_to_array( eml, E'\|' );
    fieldsLen := array_length(fields,1);
    RAISE NOTICE 'fields, array_length(fields): %,%', fields, fieldsLen;        

我明白了:

NOTICE:  eml: clientName|img_0196.jpg||mime|||size|3195562||serverFileName|upload/548a5b35003bf.img_0196.jpg
NOTICE:  fields, length(fields): {c,l,i,e,n,t,N,a,m,e,|,i,m,g,_,0,1,9,6,.,j,p,g,|,|,m,i,m,e,|,|,|,s,i,z,e,|,3,1,9,5,5,6,2,|,|,s,e,r,v,e,r,F,i,l,e,N,a,m,e,|,u,p,l,o,a,d,/,5,4,8,a,5,b,3,5,0,0,3,b,f,.,i,m,g,_,0,1,9,6,.,j,p,g},94

有人可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:2)

您错过了反斜杠:E'\|'应为E'\\|'