We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Strings
- Java Regex
- Discussions
Java Regex
Java Regex
Sort by
recency
|
645 Discussions
|
Please Login in order to post a comment
import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Scanner;
class Solution{
} public class MyRegex { public static void main(String[] args) { MyRegex regex = new MyRegex(); Scanner scanner = new Scanner(System.in);
}
my solution:
class MyRegex{ String pat = "([01]?[0-9]?[0-9]?|2[0-4]?[0-9]|2[0-5]?[0-5?])"; String pattern = "^" + pat + "\." + pat + "\." + pat + "\." + pat ; }
Here pat accepts number string only ranges between 0 to 255. Pattern make sures that IP addr should start with number 0 to 255 and "\." add point between numbers.