Q: Python IPv6 Regex pattern recognition I have been looking at recognizing IPv6 addresses from strings and replacing them with some other text.
Currently I am using the following pattern:
ipv6_pattern = re.compile(r'(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|'
                          r'([0-9a-fA-F]{1,4}:){1,7}:|'
                          r'([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|'
                          r'([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|'
                          r'([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|'
                          r'([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|'
                          r'([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|'
                          r'[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|'
                          r'fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|'
                          r'::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|'
                          r'1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|'
                          r'(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|'
                          r'([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|'
                          r'(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|'
                          r'(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))')

It works (almost) ok.
Example:
2001::85a3:0000:0000:8a2e -> CHANGED85a3:0000:0000:8a2e 
Clearly I could fix this by adding start and end of string tags to both sides of the regex pattern such that it would cover the whole string instead of only part of it.
This adds a new issue however since there are cases in which a pattern such as 
STARTOFSTRING2001::85a3:0000:0000:8a2e
STARTOFSTRING2001::85a3:0000:0000:8a2eENDOFSTRING
2001::85a3:0000:0000:8a2eENDOFSTRING

and if I add start and end of string tags these cases would not be covered. My question is then as follows:
Is there a "better" pattern I can use that allows me to catch the entire IPv6 address as well as the cases where there is text on either side of it.
