fork(20) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.util.regex.*;
  4.  
  5. class Main {
  6.  
  7. static final String[] testcases = new String[] {
  8. "'Tumblr' is an amazing app",
  9. "Tumblr is an amazing 'app'",
  10. "Tumblr is an 'amazing' app",
  11. "Tumblr is 'awesome' and 'amazing' ",
  12. "Tumblr's users' are disappointed ",
  13. "Tumblr's 'acquisition' complete but users' loyalty doubtful"
  14. };
  15.  
  16. public static void main (String[] args) throws java.lang.Exception {
  17. Pattern p = Pattern.compile("(?:^|\\s)'([^']*?)'(?:$|\\s)", Pattern.MULTILINE);
  18. for (String arg : testcases) {
  19. System.out.print("Input: "+arg+" -> Matches: ");
  20. Matcher m = p.matcher(arg);
  21. if (m.find()) {
  22. System.out.print(m.group());
  23. while (m.find()) System.out.print(", "+m.group());
  24. System.out.println();
  25. } else {
  26. System.out.println("NONE");
  27. }
  28. }
  29. }
  30. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Input: 'Tumblr' is an amazing app -> Matches: 'Tumblr' 
Input: Tumblr is an amazing 'app' -> Matches:  'app'
Input: Tumblr is an 'amazing' app -> Matches:  'amazing' 
Input: Tumblr is 'awesome' and 'amazing'  -> Matches:  'awesome' ,  'amazing' 
Input: Tumblr's users' are disappointed  -> Matches: NONE
Input: Tumblr's 'acquisition' complete but users' loyalty doubtful -> Matches:  'acquisition'