fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String frontPage = "<html>\n<head>\n<title>Hello</title>\n</head>\n" +
  13. "<body>\n<table>\n<tr align=\"left\">\n" +
  14. "<td>Hello \n<form>\n<input type=\"submit\" value=\"ok\">\n" +
  15. "</form>\n</td>\n" +
  16. "<td>World \n<form>\n<input type=\"submit\" value=\"ok\">\n" +
  17. "</form>\n</td>\n" +
  18. "</tr>\n</table>\n</body>\n</html>";
  19.  
  20. java.util.regex.Pattern p =
  21. java.util.regex.Pattern.compile(
  22. "(align=\"left\">\\n)(?<part>.*?)(<\\/form>\\n<\\/td>)",
  23. java.util.regex.Pattern.DOTALL
  24. );
  25. java.util.regex.Matcher m = p.matcher(frontPage);
  26.  
  27. List<String> parts = new ArrayList<>();
  28. while (m.find()) {
  29. System.out.println("Match: " + m.group("part") + "\n");
  30. }
  31. }
  32. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Match: <td>Hello 
<form>
<input type="submit" value="ok">