regexp_substr 当标点符号在字符串中间时忽略 (oracle)

regexp_substr ignore when punctuation in middle of string (oracle)

我正在查看文本中的大字符串。文中很多时候都有。或者特别是? ?作为分隔符。

所以我想从字符串 'Delivery Note ?Patient was at home. Delivered at home'

在家交付但不是送货单?患者在家这是我目前得到的。 下面的代码在其他方面运行良好。

已添加:考虑到下面的评论,这里使用了正则表达式,因为实际数据源中有许多排列,例如在家中分娩、在救护车中分娩、在车辆中分娩或出生救护车,在家生等等等等

任何建议表示赞赏-

with txt as (select 1 as ID,
            'Delivery Note ?Patient was at home. Delivered at home' as note_text from dual)
    select txt.*,
regexp_substr(NOTE_TEXT, '(born|birth|sv(b|d)|deliver(ed|y|ing)|vbac)[^.|?|,|(|)|;|:|-].{1,24}(vehicle|bathroom|ambulance|home|[^a-z]car([^a-z|]|$))',1,1,'i') 
    as results
    
    from txt;

看起来这就是您需要的:

with txt as (select 1 as ID,
            'Delivery Note ?Patient was at home. Delivered at home' as note_text from dual)
    select txt.*,
regexp_substr(NOTE_TEXT, '(born|birth|sv(b|d)|deliver(ed|y|ing)|vbac)[^.?,)(;:-]{1,24}(vehicle|bathroom|ambulance|home|[^a-z]car([^a-z|]|$))',1,1,'i') 
    as results    
    from txt;

如您所见,我在 [^...] 中删除了 |,因为您只需要指定不带 or 的排除字符,并在其后删除 .

结果:

        ID NOTE_TEXT                                             RESULTS
---------- ----------------------------------------------------- --------------------
         1 Delivery Note ?Patient was at home. Delivered at home Delivered at home