0

如何使用 reg 表达式找到字符串中的最后一个数字,然后将右侧的所有内容放入 c1 列,然后从最后一个数字左侧的所有内容 + 1 个字符进入 c2 列?

例如 1

string = 1234john4345 this is a test.

结果

c1 = 1234john4345  
c2 = this is a test.

例如 2

string = 1234john4345a this is a test.

结果

c1 = 1234john4345a  
c2 = this is a test.
4

1 回答 1

0
select test
    --Group 1: Match everything up to the last digit, and one other character
    --Group 2: Everything after group 1
    ,regexp_replace(test, '(.*[[:digit:]].)(.*)', '\1') c1
    ,regexp_replace(test, '(.*[[:digit:]].)(.*)', '\2') c2
from
(
    select '1234john4345 this is a test.' test from dual union all
    select '1234john4345a this is a test' test from dual
);
于 2012-04-26T04:48:16.883 回答