需要正则表达式来匹配 Oracle 12cR1 源代码中的 table 名称

Need Regular expression to match exact table name in source code in Oracle 12cR1

我正在使用 Oracle 12cR1。我需要一个 REGEX 模式来精确匹配来自 Oracle 源代码的给定 table 名称(即)匹配不能在数字、字母或下划线符号之前或之后。

我创建了一个虚拟源代码并尝试了以下操作。它没有获取所有需要的记录。我错过了什么?有这方面的正则表达式模式吗?

测试代码:

with names as (
select 'mytabname' tabname from dual union all
select 'mytabname1' from dual union all
select 'mytabname_' from dual union all
select 'mytabnameX' from dual union all
select '1mytabname' from dual union all
select '_mytabname' from dual union all
select 'Xmytabname' from dual union all
select '1mytabname_' from dual union all
select '1mytabnameX' from dual union all
select '_mytabname1' from dual union all
select 'Xmytabname1' from dual union all
select '_mytabnameX' from dual union all
select 'Xmytabname_' from dual union all
select '_mytabname_' from dual union all
select 'XmytabnameX' from dual union all
select '1mytabname1' from dual union all
select ' mytabname_' from dual union all
select '_mytabname ' from dual union all
select ' mytabname ' from dual union all
select ' mytabnameX' from dual union all
select 'Xmytabname ' from dual union all
select ' mytabname1' from dual union all
select '1mytabname ' from dual union all
select '.mytabname ' from dual union all
select ' mytabname.' from dual union all
select '.mytabname.' from dual union all
select '*mytabname' from dual union all
select ' mytabname*' from dual union all
select '*mytabname*' from dual union all
select 'defmytabnameabc' from dual)
select 'start'||tabname||'end' from names
where regexp_like(tabname, '[^a-zA-Z0-9_](mytabname)[^a-zA-Z0-9_]');

输出:

start mytabname end
start.mytabname end
start mytabname.end
start.mytabname.end
start mytabname*end
start*mytabname*end

输出遗漏了以下记录

startmytabnameend
start*mytabnameend

我一般用这个:

SELECT *
  FROM user_source
 WHERE regexp_like(text, '(\W|^)' || 'employees' || '(\W|$)', 'i');

在此处查找 Regex 的详细信息:

'i' 忽略大小写,您可以根据需要省略。

Demo for your data