in reply to Roughly matching an ipv6 address with sql wildcard

I'm not sure I understand the question. Are you asking: "Because there is a space in the value of $ip_query, it should not match $regex, but the test shows that it does match. Why is that?"

If so, it's interesting that if I take (?: $RE{net}{IPv6} ) | out of the code, it behaves as expected -- that is, the value of $ip_query does not match $regex, when $regex is just (?: [0-9a-f:%]+)

Also interesting: when $regex is just (?: $RE{net}{IPv6} ) the string does not match, as expected -- that is, the test passes.

Looks like you need a set of parens that surrounds the conjunction alternation:

my $regex = qr/\A ( (?: $RE{net}{IPv6} ) | # A full IPv6 address (?: [0-9a-f:%]+ ) # A portion of an IPv6 address with SQL % wi +ldcards ) \Z/imsx;

Replies are listed 'Best First'.
Re^2: Roughly matching an ipv6 address with sql wildcard
by neilwatson (Priest) on Sep 10, 2015 at 01:55 UTC

    You are right on all counts. I do not know why the extra brackets are needed. I must sleep on it.

    Neil Watson
    watson-wilson.ca

      The extra parens are needed in order for the anchors to do what you want. The OP regex was really saying: "if the string STARTS with an IPv6 string, OR if it ENDS with something that contains one or more IP address characters and/or percent signs".

      BTW, you might want to include underscore as a possible sql wildcard character, because it is (and can be very useful in certain cases).

        Does that mean that \A and \Z bind more tightly than | and if so, where is this precedence listed?

        Neil Watson
        watson-wilson.ca