We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String IP = in.next();
System.out.println(IP.matches(new MyRegex().pattern));
}
}
}
class MyRegex {
String A = "([01]?[0-9]{1,2}|";
String B = "2[0-4][0-9]|";
String C = "25[0-5])";
String octet = A+B+C;
String pattern = octet+"."+octet+"."+octet+"."+octet;
}
//Write your code here
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Regex
You are viewing a single comment's thread. Return to all comments →
import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Scanner;
class Solution{
} class MyRegex { String A = "([01]?[0-9]{1,2}|"; String B = "2[0-4][0-9]|"; String C = "25[0-5])"; String octet = A+B+C;
String pattern = octet+"."+octet+"."+octet+"."+octet;
} //Write your code here