fork(9) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.util.regex.*;
  4. import java.util.List;
  5.  
  6. class Program {
  7. public static void main (String[] args) throws java.lang.Exception {
  8.  
  9. String subject = "This is a string that \"will be\" highlighted when your 'regular expression' matches something.";
  10. Pattern regex = Pattern.compile("'[^']*'|\"[^\"]*\"|( )");
  11. Matcher m = regex.matcher(subject);
  12. while (m.find()) {
  13. if(m.group(1) != null) m.appendReplacement(b, "SplitHere");
  14. else m.appendReplacement(b, m.group(0));
  15. }
  16. m.appendTail(b);
  17. String replaced = b.toString();
  18. String[] splits = replaced.split("SplitHere");
  19. for (String split : splits) System.out.println(split);
  20. } // end main
  21. } // end Program
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
This
is
a
string
that
"will be"
highlighted
when
your
'regular expression'
matches
something.