【发布时间】:2014-11-12 21:34:23
【问题描述】:
如何匹配所有以loockup. 开头并以_id 结尾但不以msg 为前缀的字符串?下面是一些例子:
lookup.asset_id -> should match
lookup.msg_id -> shouldn't match
lookup.whateverelse_id -> should match
我知道 Oracle 不支持负向回溯(即(?<!))...所以我尝试使用交替显式枚举可能性:
regexp_count('i_asset := lookup.asset_id;', 'lookup\.[^\(]+([^m]|m[^s]|ms[^g])_id') <> 0 then
dbms_output.put_line('match'); -- this matches as expected
end if;
regexp_count('i_msg := lookup.msg_id;', 'lookup\.[^\(]+([^m]|m[^s]|ms[^g])_id') <> 0 then
dbms_output.put_line('match'); -- this shouldn’t match
-- but it does like the previous example... why?
end if;
第二个regexp_count 表达式不应该匹配...但它确实像第一个。我错过了什么吗?
编辑
在实际用例中,我有一个包含 PL/SQL 代码的字符串,其中可能包含多个 lookup.xxx_id 实例:
declare
l_source_code varchar2(2048) := '
...
curry := lookup.curry_id(key_val => ''CHF'', key_type => ''asset_iso'');
asset : = lookup.asset_id(key_val => ''UBSN''); -- this is wrong since it does
-- not specify key_type
...
msg := lookup.msg_id(key_val => ''hello''); -- this is fine since msg_id does
-- not require key_type
';
...
end;
我需要确定是否至少有一个错误的lookup,即除了lookup.msg_id之外的所有出现,还必须指定key_type参数。
【问题讨论】:
-
是单个字符串还是多个字符串的串联?可以有很多级别,例如 'lookup.tunnel.east.msg_id' 'lookup.tunnel.east.alternative_msg_id' 呢?有很多方法可以做到这一点,但需要更多信息。
-
不,只有一层。始终为
lookup.xyz_id(param1, param2, paramN)。
标签: regex plsql negative-lookbehind