fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.StringReader;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main {
  8. public static void main(String args[]) {
  9. String s = "";
  10. s += "<table>";
  11. s += "<tr>";
  12. s += "<td><a href=\"https://w...content-available-to-author-only...o.jp/\" ei=\"0001\" class=\"et\" target=\"_blank\">取り出したい文字列1</a></td>\n";
  13. s += "<td><a href=\"https://w...content-available-to-author-only...o.jp/\" ei=\"0002\" class=\"et\" target=\"_blank\">取り出したい文字列2</a></td>\n";
  14. s += "<td><a href=\"https://w...content-available-to-author-only...o.jp/\" ei=\"0003\" class=\"et\" target=\"_blank\">取り出したい文字列3</a></td>\n";
  15. s += "</tr>";
  16. s += "</table>";
  17. String pt = "<td><a href=\".+?\" ei=\"\\d+\" class=\"et\" target=\"_blank\">(.+?)</a></td>";
  18. Pattern p = Pattern.compile(pt);
  19. String st;
  20. try {
  21. while ((st = br.readLine()) != null) {
  22. Matcher m = p.matcher(st);
  23. if (m.find()) {
  24. System.out.println("Match");
  25. System.out.println(m.group(1));
  26. }
  27. }
  28. } catch (IOException e) {
  29. throw new RuntimeException(e);
  30. }
  31. }
  32. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
Match
取り出したい文字列1
Match
取り出したい文字列2
Match
取り出したい文字列3