Regex pl/sql反向查找后面的正则表达式
我正试图在pl/sql中实现一个正则表达式,它排除任何以字符串开头的结果Regex pl/sql反向查找后面的正则表达式,regex,oracle,plsql,Regex,Oracle,Plsql,我正试图在pl/sql中实现一个正则表达式,它排除任何以字符串开头的结果 data: exclude this: 3 include this: 3 3 cvxcvxcv3 34edfgdsfg3 Using this regexp: (?<!exclude this: )3\d{0}(\s|$) What I would expect to be returned is: exclude this: 3 <-- nothing include this: 3 <
data:
exclude this: 3
include this: 3
3
cvxcvxcv3
34edfgdsfg3
Using this regexp:
(?<!exclude this: )3\d{0}(\s|$)
What I would expect to be returned is:
exclude this: 3 <-- nothing
include this: 3 <- 3
3 <- 3
cvxcvxcv3 <- 3
34edfgdsfg3 <- the second 3 only
34edfgdsfg33 <- the last 3 only
数据:
排除此项:3
包括:3
3.
cvxcvxcv3
34edfgdsfg3
使用此regexp:
(?
当在notepad++中进行测试时,这很好,但是当在pl/sql中实现它时,它不起作用。看看类似的问题,pl/sql似乎不完全支持负回溯,但有人知道类似的构造或解决方法吗?虽然我不知道任何模拟负回溯的通用技术通过pl/sql正则表达式,在您的特定情况下,解决方案是可能的:
([^e].{13}|[^x].{12}|[^c].{11}|[^l].{10}|[^u].{9}|[^d].{8}|[^e].{7}|[^ ].{6}|[^t].{5}|[^h].{4}|[^i].{3}|[^s].{2}|[^:].|[^ ]|^)3[^0-9]?(\s|$)
负回溯适用于文本。因此,必须匹配的第一个字符的所有禁止前缀及其长度都是预先知道的。这允许使用紧凑(嗯…)规范作为必须匹配的正则表达式
并不是说我会推荐最佳实践…或任何实践
更新(处理建议):
当前的正则表达式标识匹配项,而不提供任何用于后处理的进一步信息。但是,您可以使用以下代码标识匹配项的偏移量和禁止前缀的长度:
DECLARE
s_data VARCHAR2(4000); -- This will contain the line you match against
s_matchpos BINARY_INTEGER; -- Offset of the 'interesting' part (digit '3' under the various constraints) in s_data
s_prefix VARCHAR2(100); -- The prefix part of the match
s_re VARCHAR2(4000); -- The regex
BEGIN
s_re := '([^e].{13}|[^x].{12}|[^c].{11}|[^l].{10}|[^u].{9}|[^d].{8}|[^e].{7}|[^ ].{6}|[^t].{5}|[^h].{4}|[^i].{3}|[^s].{2}|[^:].|[^ ]|^)3[^0-9]?(\s|$)';
s_prefix := regexp_replace( s_data, s_re, '\1', 1, 1); -- start at offset 1 of the data and find the first match
s_matchpos := regexp_instr( s_data, s_re ) + length(s_prefix);
END;
如上所述,不一定推荐作为最佳实践…您能解释一下有关逻辑的更多信息吗?反向工程您的记事本++代码是不可能的。目前我有一个可以工作的正则表达式,但是当查看输出时,我发现当前表达式不够,因为它返回我想要过滤的结果t进一步。例如,如果我当前有3\d{0}(\s |$)作为我的regexp。除了rogue结果(在本例中是'exclude this:3'的条目)之外,将返回我想要的所有内容。这是我需要的额外过滤。可能是我的问题不清楚。请解释您希望如何查看输出及其背后的逻辑?因此,您需要用通俗的英语解释regexIn通俗的英语背后的逻辑。此正则表达式查找数字3,只要它后面没有任何其他内容。我想要的是上面写着‘给我所有的数字3,除了数字3前面加上“排除此项”:-ommit这些结果也“编辑”:在我的示例中,当构造regexp时,它在notepad++中工作,但是pl/sql不以相同的方式支持regexp-我正在寻找一个答案,我认为这是可行的,但事实证明它不可行。它似乎做的是选择以及任何前面的字符as(最多14个)。我只想选择“3”,而不想选择其他内容。(Reg exp)。