fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.*;
  3. import java.util.regex.Pattern;
  4. import java.io.*;
  5. 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. }
Runtime error #stdin #stdout #stderr 0.06s 2841600KB
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>





<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>





stdout
Standard output is empty
stderr
Exception in thread "main" java.io.FileNotFoundException: C:\Users\Ashu\Desktop\tp.xml (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at java.io.FileInputStream.<init>(FileInputStream.java:93)
	at RegExDemo.main(Main.java:11)