正则表达是迄今为止我的弱点。 我正在尝试分解以下字符串
Node 51 Path 1 Route 4
Node 51A Path 12 Route 3
Node 5 Path 12 Route 2
Node 7B Path 1 Route 1
我需要的是Node,Node的字母,Path和Route。
我无法提取节点的字母。节点的字母是一个非数字字符,它始终跟随节点的编号,没有空格。
第2行和第2行4
Node 51A Path 12 Route 3 - Nodes letter is A
Node 5 Path 12 Route 2 - Nodes letter is NULL
Node 7B Path 1 Route 1- Nodes letter is B
到目前为止,
with gen as (
select 'Node 51 Path 1 Route 4' x from dual union all
select 'Node 51A Path 12 Route 3' x from dual union all
select 'Node 5 Path 12 Route 2' x from dual union all
select 'Node 7B Path 1 Route 1' x from dual
)
select x ,
regexp_substr(x, '(\d+)',1,1) as Node ,
regexp_substr(x, '(\d+)',1,2) as Path ,
regexp_substr(x, '(\d+)',1,3) as Route
from gen
X NODE PATH ROUTE
------------------------ ------ ------ -------
Node 51 Path 1 Route 4 51 1 4
Node 51A Path 12 Route 3 51 12 3
Node 5 Path 12 Route 2 5 12 2
Node 7B Path 1 Route 1 7 1 1
Oracle 10gR2。
答案 0 :(得分:2)
with gen as (
select 'Node 51 Path 1 Route 4' x from dual union all
select 'Node 51A Path 12 Route 3' x from dual union all
select 'Node 5 Path 12 Route 2' x from dual union all
select 'Node 7B Path 1 Route 1' x from dual
)
select x ,
regexp_substr(x, '\d+') as Node,
regexp_replace(regexp_substr(x, '\d+\S*'),'\d+') as NodeLetter ,
regexp_substr(x, '\d+',1,2) as Path ,
regexp_substr(x, '\d+',1,3) as Route
from gen