http://www.perlmonks.org?node_id=967210


in reply to Parenthesis grouping into regexes.

This is a well-solved problem. Suggest you check out Regexp::Common.

xoxo,
Andy

Replies are listed 'Best First'.
Re^2: Parenthesis grouping into regexes.
by mbethke (Hermit) on Apr 26, 2012 at 06:31 UTC

    Regexp::Common doesn't support IPv6 addresses though. Regexp::IPv6 does, however it creates quite a monster just to match the third form from RFC 4291 section 2.2 (mixed hex/decimal) that I've never seen used anywhere. This is (supposedly, I haven't tested it) a much shorter version:

    qr/^(((?=(?>.*?::)(?!.*::)))(::)?(([0-9A-F]{1,4})::?){0,5}|((?5):){6})(\2((?5)(::?|$)){0,2}|((25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\.|$)){4}|(?5):(?5))(?<![^:]:|\.)\z/i
Re^2: Parenthesis grouping into regexes.
by aramisf (Beadle) on Apr 26, 2012 at 19:48 UTC
    Pretty nice library. Didn't know it.
    Very useful indeed.

    Thanks for the tip.