Check IP Address Pattern using regex match in Java

Code:

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test
{
    public static void main(String[] args)
    {
  Scanner sc = new Scanner(System.in);
  String str = sc.next();
System.out.println(Pattern.matches("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", str));
    }
}




Ouput:

IP Address Check in Java

Previous
Next Post »