fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.*;
  3. import java.util.regex.Pattern;
  4. import java.io.*;
  5. public class RegExDemo
  6. {
  7. public static void main(String[] arg) throws Exception
  8. {
  9. //System.out.println("hey");
  10. String file = "C:\\Users\\Ashu\\Desktop\\tp.xml";
  11. String str;
  12. //String fileContents="";
  13. while((str=br.readLine())!= null)
  14. //fileContents = fileContents+"\n"+str;
  15. //System.out.println(fileContents);
  16. {sb.append(str);}
  17.  
  18. String sGroup = "<student>(<s>.*?</s>)+</student>";
  19. System.out.println("After sGroup");
  20. Pattern sPattern = Pattern.compile(sGroup);
  21. System.out.println("Creating Object sPattern");
  22. Matcher sMatcher = sPattern.matcher(sb);
  23. System.out.println("Matching");
  24. int count = 0;
  25. System.out.println("GETTING INTO THE LOOP");
  26. while(sMatcher.find())
  27. {
  28. System.out.println("IN THE LOOP");
  29. count++;
  30. System.out.println("Student: " +count);
  31. System.out.println(sMatcher.group(0));
  32. System.out.println("END OF LOOP");
  33. }
  34. }
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
<student>
	<s>ashu</s>
	<s>0544544578</s>
	<s>89</s>
</student>

<student>
	<s>ashu</s>
	<s>0544544578</s>
	<s>89</s>
</student>

<student>
	<s>ashu</s>
	<s>0544544578</s>
	<s>89</s>
</student>





compilation info
Main.java:5: error: class RegExDemo is public, should be declared in a file named RegExDemo.java
public class RegExDemo
       ^
1 error
stdout
Standard output is empty