开发者

Regex to match test<not ABC>test

I'm using Oracle regural expressions and I want to match some string, then something different to another string and then another string.

开发者_如何学C

For instance, I want to match 'testZZZtest' and 'testAAAtest', but no 'testABCtest' nor 'test bla bla ABC bla bla test'.

I'm trying the pattern 'test[^ABC]*test' as in:

select regexp_instr('bla bla bla testAZZtest bla bla bla', 'test[^ABC]*test') from dual

but it does't work (it answer 0, which means it does not match). It seems that the 'A' in 'AZZ' is the problem, because if I try:

select regexp_instr('bla bla bla testZZZtest bla bla bla', 'test[^ABC]*test') from dual

I got the answer 13 which is the position of testZZZtest in the original string.

Surely I'm missing something, but I can't find the problem. Looked for some info about negative lookahead, but I got a syntax that does not work in Oracle:

http://www.regular-expressions.info/lookaround.html


Try this:

test([^A].*|.[^B].*|..[^C].*)test

In your attempt, [^ABC]* matches 0 or more characters that aren't A, B or C. This explains why it matched ZZZ (which has no A, B or C) but not AZZ (which has an A).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜