fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Pattern;
  7. import java.util.regex.Matcher;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // your code goes here
  15.  
  16. 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";
  17.  
  18. //String patternString = "is";
  19. //Pattern pattern = Pattern.compile(patternString);
  20.  
  21. Pattern pattern1 = Pattern.compile("[a-zA-Z0-9.#,\\-&:\\\\/\n ]+");
  22. Matcher matcher = pattern1.matcher(text);
  23.  
  24. int count = 0;
  25. String correctedString = "";
  26. while(matcher.find()) {
  27. count++;
  28. System.out.println("found: " + count + " : "
  29. + matcher.start() + " - " + matcher.end() + " " + text.substring(matcher.start(), matcher.end()));
  30. correctedString+= text.substring(matcher.start(), matcher.end());
  31. }
  32. System.out.println(text);
  33. System.out.println(correctedString);
  34. }
  35. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
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