- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaRegex.java
More file actions
Latest commit
25 lines (20 loc) · 548 Bytes
/
Copy pathJavaRegex.java
File metadata and controls
25 lines (20 loc) · 548 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
packageStrings;
importjava.util.Scanner;
publicclassJavaRegex {
publicstaticvoidmain(String[] args){
Scannerin = newScanner(System.in);
while(in.hasNext()){
StringIP = in.next();
System.out.println(IP.matches(newMyRegex().pattern));
}
}
}
classMyRegex
{
Stringpattern;
publicMyRegex()
{
StringzeroTo255 = "(\\d{1,2}|(0|1)\\d{2}|2[0-4]\\d|25[0-5])";
this.pattern = zeroTo255 + "\\." + zeroTo255 + "\\." + zeroTo255 + "\\." + zeroTo255;
}
}