From 9555b9a53aac9e96c28a9450f690c4232a23bd6f Mon Sep 17 00:00:00 2001 From: Debesh Paul <139678494+debeshp6@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:07:31 +0530 Subject: [PATCH] Create JavaRegex.java --- JavaRegex.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 JavaRegex.java diff --git a/JavaRegex.java b/JavaRegex.java new file mode 100644 index 0000000..f6a7888 --- /dev/null +++ b/JavaRegex.java @@ -0,0 +1,21 @@ +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)); + } + + } +} + +//Write your code here +class MyRegex { + String num = "([01]?\\d{1,2}|2[0-4]\\d|25[0-5])"; + String pattern = num + "." + num + "." + num + "." + num; +}