POSIX 在变长字符串中搜索
POSIX Search in variable length character string
我有以下三个字符串,我想为四个示例中的每一个捕获 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")
我无法确定在 # 限定符之间放置什么,因为结果集可能是 space 然后 2 位数字,space 然后 3 位数字,space然后是 4 位数字,或者只是 4 个文本字符。
使用以下正则表达式解决
trim(substring(e.meta from '%branchnumber =>([A-Z]{4}| [0-9]{1,5}))
我有以下三个字符串,我想为四个示例中的每一个捕获 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")
我无法确定在 # 限定符之间放置什么,因为结果集可能是 space 然后 2 位数字,space 然后 3 位数字,space然后是 4 位数字,或者只是 4 个文本字符。
使用以下正则表达式解决
trim(substring(e.meta from '%branchnumber =>([A-Z]{4}| [0-9]{1,5}))