Why this regex match as expected?

I'm sorry that I don't even know if this is the right section to ask this question.

I got a regular expression that checks if a string matches the representation of an octal number in number between 0 and 77776.

The regular expression is as follows:

^ ([0-7] {0,4} |) [0-7] {4} (?) (? < = ^ 7777) [0-6] | [0-7])) $

I tested it with a .NET System.Text.RegularExpression.RegEx object within a xsd schema restriction and the expression seems to work very well. It works very well in Perl

Hovever if I write something like:

SELECT 1
FROM DUAL
WHERE REGEXP_LIKE('77777', '^([0-7]{0,4}|[0-7]{4}(?(?<=^7777)[0-6]|[0-7]))$');

The expression matches wrongly: 77777 should be out of the range "allowed" (it is not a real range, only a textual representation of it in any case)

Anyone know how to rewrite the expression in order to '77777' does not?

Hello

Yes, this is the right place to ask questions about SQL, such as REGEXP_LIKE functions.

Regular expressions in different systems have different characteristics.  As far as I know, the Oracle regular expressions have no sort of IF-THEN-ELSE logic, such as

(? (?<>

I would probably use 2 separate, such as conditions

REGEXP_LIKE (str

, ' ^ [0-7] {0,5} $'

)

AND NVL (str, 'OK') <> '77777'

Tags: Database

Similar Questions

Maybe you are looking for