2

到目前为止,正则表达式是我的弱点。我正在尝试分解以下字符串

Node 51 Path 1 Route 4
Node 51A Path 12 Route 3
Node 5 Path 12 Route 2
Node 7B Path 1 Route 1

我需要的是节点、节点的字母、路径和路由。

我无法提取节点的字母。节点的字母是一个单一的非数字字符,它总是跟在节点的编号后面,没有空格。

对于第 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

甲骨文 10gR2。

4

1 回答 1

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
于 2013-08-25T06:50:10.150 回答