/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.util.regex.Pattern; import java.util.regex.Matcher; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { // your code goes here String text= "M/s. SUNRISE DISTRIBUTORS,Shop No.1 to 4,Jai Bhavani CHS Ltd.,,Patel Nagar, M.G.Cross Road No.4,,NR.Sunny Hotel, Kandivali (W),,MUMBAI,400067,MAHARASHTRA"; //String patternString = "is"; //Pattern pattern = Pattern.compile(patternString); Pattern pattern1 = Pattern.compile("[a-zA-Z0-9.#,\\-&:\\\\/\n ]+"); Matcher matcher = pattern1.matcher(text); int count = 0; while(matcher.find()) { count++; + matcher.start() + " - " + matcher.end() + " " + text.substring(matcher.start(), matcher.end())); correctedString+= text.substring(matcher.start(), matcher.end()); } } }
Standard input is empty
found: 1 : 0 - 123 M/s. SUNRISE DISTRIBUTORS,Shop No.1 to 4,Jai Bhavani CHS Ltd.,,Patel Nagar, M.G.Cross Road No.4,,NR.Sunny Hotel, Kandivali found: 2 : 124 - 125 W found: 3 : 126 - 153 ,,MUMBAI,400067,MAHARASHTRA M/s. SUNRISE DISTRIBUTORS,Shop No.1 to 4,Jai Bhavani CHS Ltd.,,Patel Nagar, M.G.Cross Road No.4,,NR.Sunny Hotel, Kandivali (W),,MUMBAI,400067,MAHARASHTRA M/s. SUNRISE DISTRIBUTORS,Shop No.1 to 4,Jai Bhavani CHS Ltd.,,Patel Nagar, M.G.Cross Road No.4,,NR.Sunny Hotel, Kandivali W,,MUMBAI,400067,MAHARASHTRA