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.
publicstaticvoidmain(String[]args){// Class with patternclassMyRegex{Stringpattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$";}// Create a class and Scanner instancesMyRegexmyRegex=newMyRegex();Scannersc=newScanner(System.in);// Iterate on input ip addresseswhile(sc.hasNext()){Stringstr=sc.next();// Print true if it matches or false if it doesn'tSystem.out.println(str.matches(myRegex.pattern));}// Close the Scannersc.close();}
Cookie support is required to access HackerRank
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 →