限制 regexp_like 中的字符数

limiting number of characters in regexp_like

我正在挖掘诸如在家分娩、在家分娩等术语的文本字段。 我下面的代码大部分都有效。但是,如何限制字符数以限制我可能得到的误报数?

我想要第 1 行和第 2 行,而不是第 3 行。我希望将 regexp_like 语句中的字符数限制为 10 或 20 所以我会送货上门或送货上门。

with test (id, col) as
  (select 1, 'abc 3/4/16 blah blah home  delivery'                          from dual union all
   select 2, 'abc 3/4/16 blah blah 3/7/16 delivery at home xxx cc2'         from dual union all
   select 3, 'xxx 3/5/18 delivery 234 imp happened on 5/8/19 sent home 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 * from test 
where     regexp_like(col,'(home|deliver).*(deliv|birth|home)') ;

谢谢-

如果您对所获得的比赛和表现感到满意,
您可以通过将无限制的 .* 替换为长度受限的任意字符匹配器来限制 home|deliver 组和 deliv|birth|home 组之间的中间字符的长度。

您可以指定字符串中允许的中间字符的最大长度和最小长度。
下面是一个示例,组之间允许 0 - 30 个字符。

WITH TEST (ID , COL) AS
    (SELECT 1, 'abc 3/4/16 blah blah home  delivery' FROM DUAL UNION ALL
     SELECT 2, 'abc 3/4/16 blah blah 3/7/16 delivery at home xxx cc2' FROM DUAL UNION ALL
     SELECT 3, 'xxx 3/5/18 delivery 234 imp happened on 5/8/19 sent home 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 *
FROM TEST
WHERE REGEXP_LIKE(COL , '(home|deliver).{0,30}(deliv|birth|home)');

结果:

   ID                                                     COL
_____ _______________________________________________________
    1 abc 3/4/16 blah blah home  delivery
    2 abc 3/4/16 blah blah 3/7/16 delivery at home xxx cc2


2 rows selected.