diff --git a/Java/Java Regex/Solution.java b/Java/Java Regex/Solution.java new file mode 100644 index 0000000..7acf64f --- /dev/null +++ b/Java/Java Regex/Solution.java @@ -0,0 +1,22 @@ +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)); + } + + } +} +class MyRegex{ + public static final String pattern = + "(\\d{1,2}|(0|1)\\" + "d{2}|2[0-4]\\d|25[0-5])" + "\\." + + "(\\d{1,2}|(0|1)\\" + "d{2}|2[0-4]\\d|25[0-5])" + "\\." + + "(\\d{1,2}|(0|1)\\" + "d{2}|2[0-4]\\d|25[0-5])" + "\\." + + "(\\d{1,2}|(0|1)\\" + "d{2}|2[0-4]\\d|25[0-5])"; +}