Posted to tcl by oldlaptop at Wed Nov 24 06:06:43 GMT 2021view raw

  1. % set stuff {
  2. Foo: bar Baz: quux spam ham Egg: bacon bacon baked beans and spam
  3. Stuff:
  4. Yada: dada dada dada Florb: nothing
  5. }
  6.  
  7. Foo: bar Baz: quux spam ham Egg: bacon bacon baked beans and spam
  8. Stuff:
  9. Yada: dada dada dada Florb: nothing
  10.  
  11. % regexp -all -inline {([A-Z][a-z]+): ([^:]+)} $stuff
  12. {Foo: bar Baz} Foo {bar Baz} {Egg: bacon bacon baked beans and spam
  13. Stuff} Egg {bacon bacon baked beans and spam
  14. Stuff} {Yada: dada dada dada Florb} Yada {dada dada dada Florb}
  15. % lmap {whole_match key value} [regexp -all -inline {([A-Z][a-z]+): ([^:]+)} $stuff] {
  16. dict set details $key [lrange $value 0 end-1]
  17. }
  18. {Foo bar} {Foo bar Egg {bacon bacon baked beans and spam}} {Foo bar Egg {bacon bacon baked beans and spam} Yada {dada dada dada}}
  19. % puts $details
  20. Foo bar Egg {bacon bacon baked beans and spam} Yada {dada dada dada}
  21. % dict get $detail Egg
  22. bacon bacon baked beans and spam
  23.  
  24.