fork download
  1. /* l'L'l */
  2.  
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. /* scan html for pattern and match. */
  8. class tagMatch
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String line;
  13.  
  14. while ((line = r.readLine()) != null) {
  15. Pattern pattern = Pattern.compile("(<a\\shref=\"\\w.+\")\\s.+>\"(.+</a>)");
  16. Matcher matcher = pattern.matcher(line);
  17. while (matcher.find()) {
  18. // get the two groups we were looking for
  19. String group1 = matcher.group(1);
  20. String group2 = matcher.group(2);
  21.  
  22. // save groups as one string and print
  23. String groups = "";
  24. String merged = groups.format("%s%s",group1,group2);
  25. System.out.print(merged);
  26. }
  27. }
  28. }
  29. }
Success #stdin #stdout 0.08s 380160KB
stdin
<a href="<a href="http://w...content-available-to-author-only...r.com/xml-formatter.html#ad-output" target="_blank">http://w...content-available-to-author-only...r.com/xml-formatter.html#ad-output</a>">Links</a>
stdout
<a href="http://w...content-available-to-author-only...r.com/xml-formatter.html#ad-output">Links</a>