I have a text file, and loop though the file like this:
for ( int i = 0; i < this.textLines.size(); i++ ) {
String tempString = textLines.get( i );
So now I have tempString containing something like:
46.102.241.199:3128 0.2990 Transp. NN N 100% 2011-11-19 17:56:02
What I want to to is return the IP:PORT part, in this case: 46.102.241.199:3128
How can I do that?
This regex would get you an IP with an optional port. If there’s always a port remove the questionmark at the end of the line.
Note that this is a simplified validation of an IPv4 and will only match that they are one the correct format and not a valid one. And remember to add an extra backslash to escape each backslash in java.
Here’s an example in java:
Output: