fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class RegexTester
  5. {
  6. public static void main (String[] args)
  7. {
  8. String s =
  9. "This is a test [url] http://w...content-available-to-author-only...m.hk [/url]\n"
  10. + " and [img] http://w...content-available-to-author-only...c.com/test.png [/img]";
  11.  
  12. Pattern p = Pattern.compile("\\[(\\w+)\\](.+?)\\[/\\1\\]");
  13.  
  14. Matcher m = p.matcher(s);
  15. while (m.find()) {
  16. System.out.println("Match=[" + m.group(2).trim() + "]");
  17. }
  18. }
  19. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Match=[http://w...content-available-to-author-only...m.hk]
Match=[http://w...content-available-to-author-only...c.com/test.png]