fork download
  1. import java.util.regex.*;
  2.  
  3. class Ideone {
  4. public static void main (String[] args) throws java.lang.Exception {
  5. final String regex = "(?:([\\w/.-]+)\\h*=|(?!^)\\G,)\\h*((\"?)[^\",]*\\3)";
  6. final String string = "SettingName = \"Value1\",0x2,3,\"Value4 contains spaces\", \"Value5 has a space before the string that is ignored\"";
  7.  
  8. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  9. final Matcher matcher = pattern.matcher(string);
  10.  
  11. while (matcher.find()) {
  12. if (matcher.group(1) != null)
  13. System.out.println(matcher.group(1));
  14. System.out.println("\t=> " + matcher.group(2));
  15. }
  16.  
  17. }
  18. }
Success #stdin #stdout 0.13s 50628KB
stdin
Standard input is empty
stdout
SettingName
	=> "Value1"
	=> 0x2
	=> 3
	=> "Value4 contains spaces"
	=> "Value5 has a space before the string that is ignored"