fork(1) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. Pattern p = Pattern.compile("^(\\w+(?:-\\w+)?)\\s+=\\s+\"(.*)\"");
  9.  
  10. Matcher m = p.matcher("item-one = \"some new value\"");
  11. m.find();
  12. String option = m.group(1);
  13. String value = m.group(2);
  14. System.out.println(option+" -> "+value);
  15.  
  16. m = p.matcher("item = \"some value\"");
  17. m.find();
  18. option = m.group(1);
  19. value = m.group(2);
  20. System.out.println(option+" -> "+value);
  21.  
  22. }
  23. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
item-one -> some new value
item -> some value