fork(1) download
  1. import java.util.regex.*;
  2.  
  3. class UnihedronClass {
  4. public static void main (String[] args) {
  5. String input = "a =\"First Field\" b=SecondField c3= \"Third field value\" delta = \"\" e_value = five!";
  6. String regex = "\\b(\\w+)\\s*=\\s*(?:\"([^\"]*)\"|([^ ]*)\\b)";
  7. Matcher matcher = Pattern.compile(regex).matcher(input);
  8. while (matcher.find())
  9. System.out.println(matcher.group(1) + " = " +
  10. (matcher.group(2) == null ? matcher.group(3) : matcher.group(2)));
  11. }
  12. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
a = First Field
b = SecondField
c3 = Third field value
delta = 
e_value = five