regexp语句中没有前面的字符
因此,我尝试在regexp语句中使用否定回溯,并在网上查看了其他解决方案,但它们似乎对我不起作用,所以很明显我做错了什么- 我正在寻找第一行的回报,但其他的应该是空的。基本上我需要CT胸部或肺部 有什么帮助吗regexp语句中没有前面的字符,regex,oracle,Regex,Oracle,因此,我尝试在regexp语句中使用否定回溯,并在网上查看了其他解决方案,但它们似乎对我不起作用,所以很明显我做错了什么- 我正在寻找第一行的回报,但其他的应该是空的。基本上我需要CT胸部或肺部 有什么帮助吗 with test (id, description) as ( select 1, 'CT CHEST HIGH RESOLUTION, NO CONTRAST' from dual union all --want this se
with test (id, description) as (
select 1, 'CT CHEST HIGH RESOLUTION, NO CONTRAST' from dual union all --want this
select 2, 'INJECTION, THORACIC TRANSFORAMEN EPIDURAL, NON NEUROLYTIC W IMAGE GUIDANCE.' from dual union all --do not want this
select 3, 'The cow came back. But the dog went for a walk' from dual) --do not want this
select id, description, regexp_substr(description, '(?<![a-z]ct).{1,20}(CHEST|THOR|LUNG)',1,1,'i') from test;
works利用Oracle子EXPRESSION参数检查CT
我将利用子表达式的使用来使用如下模式:
'regexp_substr(description, '(^| )((ct ).*((CHEST)|(THOR)|(LUNG)))', 1, 1,'i', 2)`
-子表达式1查找行首或空格:^|
-用于查找“CT”的子表达式3:CT
-允许其他字符:*
-下颌骨5,6,7:胸部|托尔|肺
-包含子表达式3和子表达式4的子表达式2
我使用最后一个可选参数来标识我想要的子表达式2
WITH test (id, description) as (
SELECT 1
, 'CT CHEST HIGH RESOLUTION , NO CONTRAST'
FROM dual
UNION ALL --want this
SELECT 2
, 'INJECTION , THORACIC TRANSFORAMEN EPIDURAL , NON NEUROLYTIC W IMAGE GUIDANCE.'
FROM dual
UNION ALL --do not want this
SELECT 3
, 'The cow came back. But the dog went FOR a walk'
FROM dual
) --do not want this
SELECT id
, description
, regexp_substr(description, '(^| )((ct ).*((CHEST)|(THOR)|(LUNG)))', 1, 1,'i', 2)
FROM test;
仅供参考,oracle数据库不支持“向后看”或“向前看”。啊,那可不好玩!同意,“向前看”和“向后看”是正则表达式工具箱中很好的工具,非常感谢。oralce对正则表达式的实现还不错,但是你必须克服缺乏前瞻性和滞后性的缺点。使用子表达式是人们用来弥补这一缺陷的一种方法。
WITH test (id, description) as (
SELECT 1
, 'CT CHEST HIGH RESOLUTION , NO CONTRAST'
FROM dual
UNION ALL --want this
SELECT 2
, 'INJECTION , THORACIC TRANSFORAMEN EPIDURAL , NON NEUROLYTIC W IMAGE GUIDANCE.'
FROM dual
UNION ALL --do not want this
SELECT 3
, 'The cow came back. But the dog went FOR a walk'
FROM dual
) --do not want this
SELECT id
, description
, regexp_substr(description, '(^| )((ct ).*((CHEST)|(THOR)|(LUNG)))', 1, 1,'i', 2)
FROM test;