@@ -0,0 +1,1338 @@
+package java_problems.strings;%0D%0A%0D%0Aimport java.util.regex.Matcher;%0D%0Aimport java.util.regex.Pattern;%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Write a class called myRegex which will contain a string pattern. You need%0D%0A * to write a regular expression and assign it to the pattern such that it %0D%0A * can be used to validate an IP address. Use the following definition of an IP%0D%0A * address:%0D%0A * %0D%0A * IP address is a string in the form %22A.B.C.D%22, where the value of A, B, C,%0D%0A * and D may range from 0 to 255. Leading zeros are allowed. The length of%0D%0A * A, B, C, or D can't be greater than 3.%0D%0A * %0D%0A * Sample Input:%0D%0A * %0D%0A * 000.12.12.034%0D%0A * 121.234.12.12%0D%0A * 23.45.12.56%0D%0A * 00.12.123.123123.123%0D%0A * 122.23%0D%0A * Hello.IP%0D%0A */%0D%0Aclass JavaRegex %7B%0D%0A%0D%0A    public static void main(String %5B%5Dargh) %7B%0D%0A        Scanner in = new Scanner(System.in);%0D%0A        System.out.println(%22Enter IP addresses to test, each followed %22%0D%0A        %09%09%09%09   + %22by a space.%22);%0D%0A        while(in.hasNext()) %7B%0D%0A            String IP = in.next();%0D%0A            System.out.println(IP.matches(new myRegex().pattern));%0D%0A        %7D%0D%0A        in.close();%0D%0A    %7D%0D%0A%7D%0D%0A    %0D%0Aclass myRegex %7B%0D%0A%09%0D%0A%09String pattern = %22%5E(%5B01%5D?%5C%5Cd%5C%5Cd?%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D)%5C%5C.%22 +%0D%0A%09%09%09%09%09%22(%5B01%5D?%5C%5Cd%5C%5Cd?%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D)%5C%5C.%22 +%0D%0A%09%09%09%09%09%22(%5B01%5D?%5C%5Cd%5C%5Cd?%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D)%5C%5C.%22 +%0D%0A%09%09%09%09%09%22(%5B01%5D?%5C%5Cd%5C%5Cd?%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D)$%22;%0D%0A%7D

Add JavaRegex