fork(10) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "wo'rd w'ord wo'r'd";
  11. StringBuffer result = new StringBuffer();
  12. Matcher m = Pattern.compile("\\b(\\w)(\\w*)'(\\w(?:'\\w)*)").matcher(s);
  13. while (m.find()) {
  14. m.appendReplacement(result,
  15. m.group(1).toUpperCase()+m.group(2) + "'" + m.group(3).toUpperCase());
  16. }
  17. m.appendTail(result);
  18. System.out.println(result.toString());
  19.  
  20. }
  21. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
Wo'Rd W'Ord Wo'R'D