Oracle Regex排除单词(仅在找到时)

时间:2019-05-15 17:16:11

标签: oracle regex-negation word-boundary

软件: Oracle



我有一个与

匹配的查询

EXCEL.EXEEXCEL.EXE

Dropbox.exeDropbox.exe

1-2-3-4-hike.exe1-2-3-4-hike.exe

shish boom bah.exebah.exe

MS OutlookMS Outlook

但是,我希望排除.exe


换句话说

EXCEL.EXEEXCEL

Dropbox.exeDropbox

1-2-3-4-hike.exe1-2-3-4-hike

shish boom bah.exebah

MS OutlookMS Outlook


这是先前的工作查询:

CASE WHEN REGEXP_LIKE(M.ENDPOINTAPPLICATIONNAME, '\.exe', 'i')
     THEN REGEXP_SUBSTR(M.ENDPOINTAPPLICATIONNAME,'[a-zA-Z0-9]\S*\.exe',1,1,'i')
     ELSE M.ENDPOINTAPPLICATIONNAME
END

这是我修改后的查询错误-除其他外,尝试!(.exe)-请进行指导

CASE WHEN REGEXP_LIKE(M.ENDPOINTAPPLICATIONNAME, '\.exe', 'i')
     THEN REGEXP_SUBSTR(M.ENDPOINTAPPLICATIONNAME,'[a-zA-Z0-9]\S*\!(.exe)',1,1,'i')
     ELSE M.ENDPOINTAPPLICATIONNAME
END

1 个答案:

答案 0 :(得分:1)

您可以使用正则表达式捕获组,并在所需的子字符串周围加上一个组(括号)。例如:

with test_vals AS (
    SELECT 'EXCEL.EXE' AS ENDPOINTAPPLICATIONNAME FROM dual
    UNION ALL SELECT 'Dropbox.exe' FROM dual
    UNION ALL SELECT '1-2-3-4-hike.exe' FROM dual
    UNION ALL SELECT 'shish boom bah.exe' FROM dual
    UNION ALL SELECT 'MS Outlook' FROM dual
)

SELECT CASE WHEN REGEXP_LIKE(M.ENDPOINTAPPLICATIONNAME, '\.exe', 'i')
           THEN REGEXP_SUBSTR(
                  M.ENDPOINTAPPLICATIONNAME,'([a-zA-Z0-9]\S*)\.exe',1,1,'i',1 /* Only return result of first capturing group */
               )
           ELSE M.ENDPOINTAPPLICATIONNAME
       END
FROM test_vals m