Files
HackerRank-Solutions/Java/Strings/Java Regex/Solution.java
T

28 lines
738 B
Java
Raw Normal View History

2017-02-12 00:31:12 -08:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-02-12 00:31:12 -08:00
2017-02-24 00:24:47 -06:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
class Solution {
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));
}
}
}
2017-02-09 02:34:19 -08:00
/*
[01]?\\d{1,2} matches numbers 0-199.
2[0-4]\\d matches numbers 200-249
25[0-5] matches numbers 250-255
*/
class MyRegex {
String num = "([01]?\\d{1,2}|2[0-4]\\d|25[0-5])";
String pattern = num + "." + num + "." + num + "." + num;
2017-02-24 00:24:47 -06:00
}