Without making a statement about better-suited Java classes that can handle IP addreses in a structured manner...
You can add exceptions to a regular expression using negative look-aheads:
String numIPRegex = "(?!(?:93\\.153\\.31\\.151|10\\.0\\.0\\.1)(?::27002)?)\\d{1,3}(?:\\.\\d{1,3}){3}(?::\\d{1,5})?";
Explanation:
(?! # start negative look-ahead
(?: # start non-capturing group
93\.153\.31\.151 # exception address #1
| # or
10\.0\.0\.1 # exception address #2
) # end non-capturing group
(?: # start non-capturing group
:27002 # port number
)? # end non-capturing group; optional
) # end negative look-ahead
\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})? # your original expression
Of course the other obvious alternative would be to test the exceptions up-front one by one and just return false if one exceptions matches. Wrapping them up all up in one single big regex will quickly become very ugly.
InetAddresswhich can detect correctly formatted addresses,Integer.parseInt()which can parse integers, andindexOf()inString. And, if you use Guava, you also haveHostAndPort.SocketAddress?InetSocketAddress.createUnresolved()is even better (especially sinceInetAddressmay attempt name resolution).