fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String t1 = "test1:testVar('varName', 'ns2:test')";
  13. String t2 = "test2:testVar('varName', 'ns2:test', 'defValue')";
  14. String patternString = "\\('.*?',\\s*('.*?:.*?').*\\)";
  15. Pattern pattern = Pattern.compile(patternString);
  16. Matcher matcher = pattern.matcher(t1);
  17. while (matcher.find()){
  18. System.out.println(matcher.group(1));
  19. }
  20. matcher = pattern.matcher(t2);
  21. while (matcher.find()){
  22. System.out.println(matcher.group(1));
  23. }
  24. }
  25. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
'ns2:test'
'ns2:test'