fork download
  1. import java.util.*;
  2. class Ideone
  3. {
  4. public static void main (String[] args) throws java.lang.Exception
  5. {
  6. String s =" //wont won't won't ";
  7. String regex = "[\\s+/,.!_\\-?;:]+|\\B'|'\\B";
  8. String[] w = s.split(regex);
  9. System.out.println(Arrays.toString(w));
  10. String[] w2 = s.replaceFirst("^(?:"+regex+")+", "").split(regex);
  11. System.out.println(Arrays.toString(w2));
  12. }
  13. }
Success #stdin #stdout 0.12s 36396KB
stdin
Standard input is empty
stdout
[, wont, won't, won't]
[wont, won't, won't]