fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String text = "example=3&testing='f&tmp'";
  9. Pattern p = Pattern.compile("[^&\\s=]+=(?:'[^']*'|[^\\s&]*)");
  10. Matcher m = p.matcher(text);
  11. List<String> res = new ArrayList<>();
  12. while(m.find()) {
  13. res.add(m.group());
  14. }
  15. System.out.println(res);
  16. }
  17. }
Success #stdin #stdout 0.09s 52400KB
stdin
Standard input is empty
stdout
[example=3, testing='f&tmp']