【问题标题】:REGEXP_SUBSTR AssistenceREGEXP_SUBSTR 协助
【发布时间】:2013-08-27 21:33:41
【问题描述】:

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

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

Oracle 10gR2。

【问题讨论】:

    标签: regex oracle oracle10g


    【解决方案1】:
    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
    

    【讨论】:

    • 因此您提取了整个节点并删除了任何数字。好的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多