I can't seem to find out why this regular expression is not working in PL/SQL
.
if ( REGEXP_LIKE(v,'/^(?>(?>([a-f0-9]{1,4})(?>:(?1)){7}|(?!(?:.*[a-f0-9](?>:|$)){8,})((?1)(?>:(?1)){0,6})?::(?2)?)|(?>(?>(?1)(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})(?3)?::(?>((?1)(?>:(?1)){0,4}):)?)?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?4)){3}))$/iD') ) then
It's for validating IPv4 and IPv6, it came from here: https://stackoverflow.com/a/1934546/3112803
Not sure if this has anything to do with it but I also asked this question about the D
flag on the end: What Does This Regular Expression (RegEx) Flag Mean /iD
For some reason this regular expression works for most of my tests on this site: http://regex101.com/ but in PL/SQL
everything is invalid.
What I mean by most is that there are some cases where I find it fails, but I've been searching for days and this is the best one I could find that is under 512 characters (512 is the limit when using REGEXP_LIKE
in PL/SQL
)
I'd appreciate any help. Thanks!
These are the test cases I'm using...
{1: Initial address, regex should say valid/match}
select isValid('2001:0db8:0000:0000:0000:ff00:0042:8329','ipv6') from dual;
{2: After removing all leading zeroes, regex should say valid/match}
select isValid('2001:db8:0:0:0:ff00:42:8329','ipv6') from dual;
{3: After omitting consecutive sections of zeroes, regex should say valid/match}
select isValid('2001:db8::ff00:42:8329','ipv6') from dual;
{4: The loopback address, regex should say valid/match}
select isValid('0000:0000:0000:0000:0000:0000:0000:0001','ipv6') from dual;
{5: The loopback address be abbreviated to ::1 by using both rules, regex should say valid/match}
select isValid('::1','ipv6') from dual;
{6: This should be valid/match}
select isValid('ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:192.168.158.190','ipv6') from dual;
{7: This should be valid/match}
select isValid('::','ipv6') from dual;
{8: IPv6 applications to communicate directly with IPv4 applications, regex should say valid/match}
select isValid('0:0:0:0:0:ffff:192.1.56.10','ipv6') from dual;
{9: should NOT be valid/match}
select isValid('::ffff:192.1.56.10/96','ipv6') from dual;
{old formats used for tunneling, these should NOT be valid/matches}
{10}
select isValid('0:0:0:0:0:0:192.1.56.10','ipv6') from dual;
{11}
select isValid('::192.1.56.10/96','ipv6') from dual;
{These 4 should be valid/match}
{12}
select isValid('::FFFF:129.144.52.38','ipv6') from dual;
{13}
select isValid('::129.144.52.38','ipv6') from dual;
{14}
select isValid('::FFFF:d','ipv6') from dual;
{15}
select isValid('1080:0:0:0:8:800:200C:417A','ipv6') from dual;
{These 4 should NOT be valid/match}
{16}
select isValid('::FFFF:d.d.d','ipv6') from dual;
{17}
select isValid('::FFFF:d.d','ipv6') from dual;
{18}
select isValid('::d.d.d','ipv6') from dual;
{19}
select isValid('::d.d','ipv6') from dual;
I was told test #6 was wrong, ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:192.168.158.190
is not a valid IPv6 address, is that correct?
Test cases 8-11 came from here: http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzai2%2Frzai2ipv6addrformat.htm but I was told 10&11 are no longer used.