fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String regex = "^(?:(?:Fwd|Re)\\h*:\\h*)+";
  12. String string = "Fwd : Re : Re: Many\n"
  13. + "Re : Re: Many\n"
  14. + "Re: Re: Many\n"
  15. + "Re: Many\n"
  16. + "Re: Many\n"
  17. + "RE: Presidential Ballots for Florida\n"
  18. + "RE: (no subject)\n"
  19. + "Request - should not match anything\n"
  20. + "this is the subject\n"
  21. + "Re: Fwd";
  22.  
  23. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
  24. Matcher matcher = pattern.matcher(string);
  25. String result = matcher.replaceAll("");
  26.  
  27. System.out.println(result);
  28. }
  29. }
Success #stdin #stdout 0.09s 33892KB
stdin
Standard input is empty
stdout
Many
Many
Many
Many
Many
Presidential Ballots for Florida
(no subject)
Request - should not match anything
this is the subject
Fwd