0

The following Oracle regular expressions do not work and I don't know why.

"Does not start with 'abc'":

^[^(abc)]

"Does not end with 'abc'":

[^(abc)]$

The problem is that the Oracle regex engine does not seem to recognize the 'abc' string as a unit, but only is looking at the letters individually. The parentheses () are supposed to create a string unit. So I don't know what is going on. I used the square brackets only because I believe the 'not' operator ^ only operates inside the brackets, otherwise the ^ is recognized as start of line.

For reference: http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_re.htm

4

2 回答 2

3

像这样测试不匹配可能会变得复杂,所以我建议测试匹配并否定结果。

不以abc

WHERE NOT REGEXP_LIKE(myString, '^abc')

不以abc:

WHERE NOT REGEXP_LIKE(myString, 'abc$')

至于为什么它不起作用,正如@DavidKnipe 在他的回答中所说:这是因为您正在使用字符类。正则表达式^[^(abc)]解析如下:

  • 第一个^说“锚定到字符串的开头”
  • The[^(abc)]是一个字符类,它表示“匹配任何单个字符,只要它不是(or aor bor or cor )”。
于 2013-06-13T19:40:29.790 回答
0

^否定运算符仅适用于字符类。但是你不应该使用字符类。我不知道 Oracle 正则表达式是否允许环视操作(前瞻和后瞻)。如果他们这样做,请使用^(?!abc)and (?<!abc)$

于 2013-06-13T19:41:30.500 回答