Oracle 使用regexp_substr捕获两个单词之间的所有字符(包括字符串的开头和结尾

Oracle 使用regexp_substr捕获两个单词之间的所有字符(包括字符串的开头和结尾,oracle,regexp-substr,Oracle,Regexp Substr,所以我一直在使用类似regexp_的,而不是regexp_substr- 但是在下面的字符串中 'abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2' '3/10/18 bla bla imp-3/9/17 xfe 334 3/4/13' I want to capture imp 2/8/15 xxx cc2 imp-3/9/17 xfe 在regexp_like中,它只是regexp_like('abc 3/4/16 blah blah 3

所以我一直在使用类似regexp_的,而不是regexp_substr- 但是在下面的字符串中

'abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2' 
'3/10/18 bla bla imp-3/9/17 xfe 334 3/4/13'

I want to capture 
imp 2/8/15 xxx cc2
imp-3/9/17 xfe 
在regexp_like中,它只是regexp_like('abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2','(imp)。{0,20}(cc2|xfe'),但它与regexp_substr的工作方式不同

我尝试过在下面使用此代码,但没有成功

with test (id, col) as
      (select 1, 'abc 3/4/16 blah blah IMP 3/7/16'                     from dual union all
      select 2, 'abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2'      from dual union all
      select 3, 'xxx 3/5/18 ccdd 234 imp happened on 5/8/19 some 23f' from dual union all
      select 4, '3/10/18 bla bla imp-3/9/17 xfe 334 3/4/13 x'         from dual
      )
   select id,
      regexp_substr('(imp).*(xxx|xfe)',1) result
  from test;
需要考虑资本化

欢迎提出建议。
谢谢

您在查询中根本没有使用
col

试试这个:

with test (id, col) as
      (select 1, 'abc 3/4/16 blah blah IMP 3/7/16'                     from dual union all
      select 2, 'abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2'      from dual union all
      select 3, 'xxx 3/5/18 ccdd 234 imp happened on 5/8/19 some 23f' from dual union all
      select 4, '3/10/18 bla bla imp-3/9/17 xfe 334 3/4/13 x'         from dual
      )
   select id,
      regexp_substr(col, '(imp).*(xxx|xfe)',1, 1) result -- use occurance as 1, last parameter
  from test;


干杯!!

是的,col可能会有帮助!今天早上还没有足够的咖啡。谢谢你抓住这个问题!问题-我的字符串已经很长了,可以重复如何限制到第一个字符串并去掉其余的字符串?当发生参数为1时,这将返回第一个发生。在应答中以及在db fiddleI ma中仍然更新得到真正的字符串之后,要尝试并发布真实的示例-需要小心,因为这是真实的PHI信息。好的,我改变了,它是regexp_substr(col),(imp){0,20}(xxx | xfe'),1,1)结果,这样更好,但是如果我想结束这个词,那么让我们说重要的,或者如果我想切换它,那么重要的是regexp|substr(col,“(xxx){0,20}(imp)'1,1)