/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/i
/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/ai
^([\dA-F]{1,4}:|((?=.*(::))(?!.*\3.+\3))\3?)([\dA-F]{1,4}(\3|:\b)|\2){5}(([\dA-F]{1,4}(\3|:\b|$)|\2){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z
/^(((?=.*(::))(?!.*\3.+\3))\3?|[\dA-F]{1,4}:)([\dA-F]{1,4}(\3|:\b)|\2){5}(([\dA-F]{1,4}(\3|:\b|$)|\2){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/i
^(((?=.*(::))(?!.*\3.+\3))\3?|[\dA-F]{1,4}:)([\dA-F]{1,4}(\3|:\b)|\2){5}(([\dA-F]{1,4}(\3|:\b|$)|\2){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\Z
^(((?=.*(::))(?!.*\3.+\3))\3?|[0-9A-F]{1,4}:)([0-9A-F]{1,4}(\3|:\b)|\2){5}(([0-9A-F]{1,4}(\3|:\b|$)|\2){2}|(((2[0-4]|1[0-9]|[1-9])?[0-9]|25[0-5])\.?\b){4})\z
/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i
([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:([0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{0,4}|:[0-9A-Fa-f]{1,4})?|(:[0-9A-Fa-f]{1,4}){0,2})|(:[0-9A-Fa-f]{1,4}){0,3})|(:[0-9A-Fa-f]{1,4}){0,4})|:(:[0-9A-Fa-f]{1,4}){0,5})((:[0-9A-Fa-f]{1,4}){2}|:(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\.(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])){3})|(([0-9A-Fa-f]{1,4}:){1,6}|:):[0-9A-Fa-f]{0,4}|([0-9A-Fa-f]{1,4}:){7}:
Convert Atomic-Group to Positive-Lookahead & Backreference (ECMA/Python/TCL ARE) (?>regex) (?=(regex))\1 Convert *+ to Atomic group (.NET/Perl/Ruby)* regex*+ (?>regex*) Convert ++ to Atomic group (.NET/Perl/Ruby)* regex++ (?>regex+) Convert ?+ to Atomic group (.NET/Perl/Ruby)* regex?+ (?>regex?) Convert {n,m}+ to Atomic group (.NET/Perl/Ruby)* regex{n,m}+ (?>regex{n,m}) Convert *? to alternation (XML) regex*? (|regex)* Convert +? to alternation (XML) regex+? regex(|regex)* Convert ?? to alternation (XML) regex?? (|regex) Convert {n,}? to alternation (XML) regex{n,}? regex{n}(|regex)* Convert {n,m}? to alternation (XML) regex{n,m}? regex{n}(|regex){m-n} Convert conditional to Lookaround (JAVA/ECMA/Python/Ruby/Tcl ARE) (?(?=regex)then|else) (?=regex)then|(?!regex)else (?(?!regex)then|else) (?!regex)then|(?=regex)else Convert conditional to Lookaround (JAVA/Python) (?(?<=regex)then|else) (?<=regex)then|(?<!regex)else (?(?<!regex)then|else) (?<!regex)then|(?<=regex)else Convert comment to Positive-Lookahead & alternation (JAVA)** (?#comment) (?=|\Qcomment\E) Convert comment to Positive-Lookahead & alternation (JAVA/ECMA)*** (?#comment) (?=|comment) Convert ? to {n,m} (POSIX BRE) regex? regex\{0,1\} Convert + to {n,} (POSIX BRE) regex+ regex\{1,\} Force capture group to be non-true/empty (Java/Perl/PCRE/ECMA/Python/Ruby/Tcl ARE)**** $(?!\1) [End of regex] (?!.*$\1) [In the regex] * = Also usable for ECMA/Phyton/TCL ARE when converting the Atomic-Group to Positive-Lookahead & Backreference ** = \E is not allowed as part of the comment *** = Meta characters may be needed to be escaped **** = Capture groups containing only a newline token might cause problems.