これを試して:
^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:[.:]\b([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
説明
# ^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?:[.:]\b([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$
#
# Assert position at the beginning of the string «^»
# Match the regular expression below «(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}»
# Exactly 3 times «{3}»
# Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])»
# Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
# Match the characters “25” literally «25»
# Match a single character in the range between “0” and “5” «[0-5]»
# Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
# Match the character “2” literally «2»
# Match a single character in the range between “0” and “4” «[0-4]»
# Match a single character in the range between “0” and “9” «[0-9]»
# Or match regular expression number 3 below (attempting the next alternative only if this one fails) «1[0-9][0-9]»
# Match the character “1” literally «1»
# Match a single character in the range between “0” and “9” «[0-9]»
# Match a single character in the range between “0” and “9” «[0-9]»
# Or match regular expression number 4 below (the entire group fails if this one fails to match) «[1-9]?[0-9]»
# Match a single character in the range between “1” and “9” «[1-9]?»
# Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
# Match a single character in the range between “0” and “9” «[0-9]»
# Match the character “.” literally «\.»
# Match the regular expression below «(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])»
# Match either the regular expression below (attempting the next alternative only if this one fails) «25[0-5]»
# Match the characters “25” literally «25»
# Match a single character in the range between “0” and “5” «[0-5]»
# Or match regular expression number 2 below (attempting the next alternative only if this one fails) «2[0-4][0-9]»
# Match the character “2” literally «2»
# Match a single character in the range between “0” and “4” «[0-4]»
# Match a single character in the range between “0” and “9” «[0-9]»
# Or match regular expression number 3 below (attempting the next alternative only if this one fails) «1[0-9][0-9]»
# Match the character “1” literally «1»
# Match a single character in the range between “0” and “9” «[0-9]»
# Match a single character in the range between “0” and “9” «[0-9]»
# Or match regular expression number 4 below (the entire group fails if this one fails to match) «[1-9]?[0-9]»
# Match a single character in the range between “1” and “9” «[1-9]?»
# Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
# Match a single character in the range between “0” and “9” «[0-9]»
# Match the regular expression below «(?:[.:]\b([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?»
# Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
# Match a single character present in the list “.:” «[.:]»
# Assert position at a word boundary «\b»
# Match the regular expression below and capture its match into backreference number 1 «([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])»
# Match either the regular expression below (attempting the next alternative only if this one fails) «[1-9][0-9]{0,3}»
# Match a single character in the range between “1” and “9” «[1-9]»
# Match a single character in the range between “0” and “9” «[0-9]{0,3}»
# Between zero and 3 times, as many times as possible, giving back as needed (greedy) «{0,3}»
# Or match regular expression number 2 below (attempting the next alternative only if this one fails) «[1-5][0-9]{4}»
# Match a single character in the range between “1” and “5” «[1-5]»
# Match a single character in the range between “0” and “9” «[0-9]{4}»
# Exactly 4 times «{4}»
# Or match regular expression number 3 below (attempting the next alternative only if this one fails) «6[0-4][0-9]{3}»
# Match the character “6” literally «6»
# Match a single character in the range between “0” and “4” «[0-4]»
# Match a single character in the range between “0” and “9” «[0-9]{3}»
# Exactly 3 times «{3}»
# Or match regular expression number 4 below (attempting the next alternative only if this one fails) «65[0-4][0-9]{2}»
# Match the characters “65” literally «65»
# Match a single character in the range between “0” and “4” «[0-4]»
# Match a single character in the range between “0” and “9” «[0-9]{2}»
# Exactly 2 times «{2}»
# Or match regular expression number 5 below (attempting the next alternative only if this one fails) «655[0-2][0-9]»
# Match the characters “655” literally «655»
# Match a single character in the range between “0” and “2” «[0-2]»
# Match a single character in the range between “0” and “9” «[0-9]»
# Or match regular expression number 6 below (the entire group fails if this one fails to match) «6553[0-5]»
# Match the characters “6553” literally «6553»
# Match a single character in the range between “0” and “5” «[0-5]»
# Assert position at the end of the string (or before the line break at the end of the string, if any) «$»