parsing - Checking if a string can be an IP address in java -


this question has answer here:

my program takes several arguments, 1 of has ip address specify server should trying connect to. there easy way check whether argument program has been given can expressed ip address?

use regex match ip address:

^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ 

i believe there related answer here.

excerpt:

private static final string pattern =          "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +         "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +         "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +         "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";  public static boolean validate(final string ip){                  pattern pattern = pattern.compile(pattern);       matcher matcher = pattern.matcher(ip);       return matcher.matches();              } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -