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. final String regex = "(?:\\b(MyObject)\\h*\\{\\h*(?=[^\\{}]*\\})|\\G(?!^))(?:(?:nothingSpecial|privateEmail)='([^'\\n,]+)'|[^\\s=]+='[^'\\n,]*')(?:,\\h*)?";
  12. final String string = "YourObject{nothingSpecial='Word1', secretData='Word2', privateEmail='Word3'}\n"
  13. + "MyObject { nothingSpecial='Word1', secretData='Word2', privateEmail='Word3'}\n"
  14. + "TheirObject{nothingSpecial='Word1', secretData='Word2', privateEmail='Word3'}";
  15.  
  16. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  17. final Matcher matcher = pattern.matcher(string);
  18.  
  19. while (matcher.find()) {
  20. for (int i = 1; i <= matcher.groupCount(); i++) {
  21. if (matcher.group(i) != null) {
  22. System.out.println(matcher.group(i));
  23. }
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0.12s 34148KB
stdin
Standard input is empty
stdout
MyObject
Word1
Word3