-1

I have an IP address for which I want to define a regular expression to write it in its proper format. Please suggest a way in which I can achieve this.

1
  • 1
    public static boolean isValidIP(String ipAddr){ Pattern ptn = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$"); Matcher mtch = ptn.matcher(ipAddr); return mtch.find(); } This will work Commented Feb 9, 2016 at 9:16

1 Answer 1

0

You may try this one :

^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$
Sign up to request clarification or add additional context in comments.

1 Comment

Does not even catch all ip addresses: ::1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.