This is my code in which I am trying to enter an IP Adress and check if it matches with the guidelines - Number of digits less than 3, and numbers between 0-255. Eg - 111.245.0.11 But every time I run the program, the matches method is outputting false, whatever be the input.
MAIN CLASS
package Rough;
import java.util.Scanner;
public class Regex
{
public static void main(String args[])throws Exception
{
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine())
{
String ip = sc.next();
System.out.println(ip.matches(new MyRegex().pattern));
}
}
}
MYRegex Class
package Rough;
public class MyRegex extends Regex
{
String limit = "(\\d{1,2} | (0,1)\\d{2} | 2[0-4]\\d | 25[0-5])";
public String pattern = limit+"\\."+ limit + "\\."+ limit + "\\." + limit;
}