由于您知道端口的长度始终为4,因此您可以根据后面的冒号和4位数字进行拆分:
String test = "176.32.37.27:777754.38.156.202:777751.68.208.5:7777";
System.out.println(
Arrays.toString(
test.split("(?<=:\\d{4})")
)
);
Run Code Online (Sandbox Code Playgroud)
输出量
[176.32.37.27:7777, 54.38.156.202:7777, 51.68.208.5:7777]
Run Code Online (Sandbox Code Playgroud)
也可以看看
在Java模式API中落后。