我有以下三个字符串,我想捕获四个示例中每个示例的branch_number结果。我正在使用PostgreSQL 8.4
ex.1) "decision => approved , branch_number => 1126 , alpha"
ex.2) "decision => counter , branch_number => 249 , beta"
ex.3) "decision => declined , branch_number =>NULL, gamma"
ex.4) "decision => declined , branch_number => 91"
我当前的查询如下,相应的结果和预期结果:
trim(substring(replace(e.meta,'_','') from '%branchnumber =>#"_____#"%' for '#'))
results 1) "1126" (desired "1126")
results 2) "249" (desired "249")
results 3) "NULL," (desired "NULL")
results 4) <null> (desired "91")
我无法确定#限定符之间的内容,因为结果集可能是2位数的空格,3位数的空格,4位数的空格,或者只是4个文本字符。
答案 0 :(得分:0)
使用以下正则表达式解决
trim(substring(e.meta from '%branchnumber =>([A-Z]{4}| [0-9]{1,5}))