You are viewing a single comment's thread. Return to all comments →
A simple approach is:
String zeroTo255 = "(\\d{1,2}|(0|1)\\d{2}|2[0-4]\\d|25[0-5])"; public String pattern = zeroTo255 + "\\." + zeroTo255 + "\\." + zeroTo255 + "\\." + zeroTo255;
1) \\d{1,2} catches any one or two digit number
2) (0|1)\\d{2} catches any three digit number starting with 0 or 1.
3) 2[0-4]\\d catches numbers between 200 and 249.
4) 25[0-5] catches numbers between 250 and 255.
Note that \d represents digits in regular expressions, same as [0-9]
Edit: Replaced "." with "\." as suggested in some of the comments
Seems like cookies are disabled on this browser, please enable them to open this website
Java Regex
You are viewing a single comment's thread. Return to all comments →
A simple approach is:
1) \\d{1,2} catches any one or two digit number
2) (0|1)\\d{2} catches any three digit number starting with 0 or 1.
3) 2[0-4]\\d catches numbers between 200 and 249.
4) 25[0-5] catches numbers between 250 and 255.
Note that \d represents digits in regular expressions, same as [0-9]
Edit: Replaced "." with "\." as suggested in some of the comments