File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ https://www.hackerrank.com/challenges/java-regex/problem
3+ */
4+ import java .util .regex .Matcher ;
5+ import java .util .regex .Pattern ;
6+ import java .util .Scanner ;
7+
8+ class Solution {
9+
10+ public static void main (String [] args ){
11+ Scanner in = new Scanner (System .in );
12+ while (in .hasNext ()){
13+ String IP = in .next ();
14+ System .out .println (IP .matches (new MyRegex ().pattern ));
15+ }
16+
17+ }
18+ }
19+
20+ //Write your code here
21+ class MyRegex {
22+
23+ /*
24+ matcher-- used to search the pattern
25+ pattern- to be used in search
26+ 0-9--> [0-9] // [0-9] any value range from 0 to 9
27+ 09-99 --> [0-9][0-9] ......bocz leading zero is allowed
28+ 099-199 --> (0|1)[0-9][0-9] // (0|1) choose either 0 or 1
29+ 200-249--> 2 [0-4][0-9]
30+ 250-254 --> 25 [0-4]
31+ */
32+ String value ="([0-9]|[0-9][0-9]|(0|1)[0-9][0-9]|2[0-4][0-9]|25[0-5])" ;
33+
34+ String pattern =value +"." +value +"." +value +"." +value ;
35+
36+ }
You can’t perform that action at this time.
0 commit comments