0

I've some text in following form

29secs  183.207.224.50      84  flag China  

HTTP    High +KA
29secs  120.203.214.206     3128    flag China  

HTTPS   High +KA
29secs  183.207.232.193     8080    flag China  

HTTPS   High +KA
29secs  60.29.248.142       8080    flag China  

HTTPS   High +KA
29secs  211.162.0.162       80  flag China  

HTTPS   High +KA
29secs  111.161.126.99      80  flag China  

HTTPS   High +KA
29secs  202.119.25.228      9999    flag China 

It's just some data from public proxy server provider. I just want to get IP address and Port so I'm using following regular expression

[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\s+[0-9]{1,5}

Now it's selecting all the IP addresses and Port. But I want to select everything else which is not IP address and Port so that I can delete them to just get IPs and Port. Can someone tell me how can I select everything else which is not fulfilling regular expression requirement?? Thank You!

Zohaib Aslam
  • 585
  • 1
  • 4
  • 15
  • 1
    regex engines return entire lines that match, usually. You'd need to establish capture groups so you can slice out the "isn't an ip/port" stuff. – Marc B Apr 22 '15 at 18:08
  • 1
    what you really want are capture groups, which are going to be way easier to implement – Jonesopolis Apr 22 '15 at 18:08
  • 2
    Are you doing this in both `java` and `c#` or are you just tag spamming for visibility? If the latter, please don't do that and keep the tags relevant to your question. – tnw Apr 22 '15 at 18:09
  • I'm implementing in both @tnw – Zohaib Aslam Apr 22 '15 at 18:11
  • I'm not sure what `select` means with java.util.regex. If it was _delete everything that matches_, `Matcher.replaceAll("")` should do the trick. If it was _get me the next SubSequence not matching_, do a `find`. If no match, the entire CharSequence is the result. If the match doesn't start at zero, your result is from zero to `start()`; otherwise, recurse on SubSequence from `end()`. – greybeard Apr 22 '15 at 18:30
  • (If the question is what would be a promising String literal for dotted IP addresses, remember that backslashes need to be escaped. Picket fence syndrome, anyone?) – greybeard Apr 22 '15 at 18:32
  • The possible duplicated question answers the problem using bash, OP is asking for a solution using both Java and C# – higuaro Apr 22 '15 at 19:05

0 Answers0