1

I am trying to define a regex that matches string with numbers and it's not begining with 40821, so '40822433598347597' matches and '408211' not. So, I've tried

^(?!40821)\d+

Works perfectly in my regex editor, but still doesnt work in oracle. I know, it's very easy to use where not but my goal is to do it using only regex. Please, some pieces of advice, what am I doing somthing wrong?

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
Skeeve
  • 1,205
  • 3
  • 16
  • 31
  • 1
    do you really need regex for this..you can use `SUBSTR( source_string, 0,4) NOT LIKE '40821'`..not sure if this would work – Anirudha Jun 24 '13 at 17:10

2 Answers2

3

According to this question, negative lookahead and lookbehind are not supported in Oracle.

One way would be to explicitly enumerate the possibilities using alternation. In your case it would be something like:

^([012356789]|4[123456789]|40[012345679]|408[013456789]|4082[023456789])
Community
  • 1
  • 1
lc.
  • 113,939
  • 20
  • 158
  • 187
  • 1
    Not sure if Oracle supports shortcuts like `\d` and `\D`, but if it does this can be shortened to `^([^\D4]|4[^\D0]|40[^\D8]|408[^\D2]|4082[^\D1])` – Andrew Clark Jun 24 '13 at 16:49
0

I think you try to use negative lookbehind:

(?<!a)b matches a "b" that is not preceded by an "a"

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

That kind of Perl's sytax is not supported by Oracle.

the_slk
  • 2,172
  • 1
  • 11
  • 10