- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
Latest commit
28 lines (22 loc) · 662 Bytes
/
Copy pathsolution.java
File metadata and controls
28 lines (22 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// https://github.com/Utkarsh299-tech
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
importjava.util.Scanner;
classSolution{
publicstaticvoidmain(String[] args){
Scannerin = newScanner(System.in);
while(in.hasNext()){
StringIP = in.next();
System.out.println(IP.matches(newMyRegex().pattern));
}
}
}
/*
[01]?\\d{1,2} matches numbers 0-199.
2[0-4]\\d matches numbers 200-249
25[0-5] matches numbers 250-255
*/
classMyRegex {
Stringnum = "([01]?\\d{1,2}|2[0-4]\\d|25[0-5])";
Stringpattern = num + "." + num + "." + num + "." + num;
}