Posted to tcl by dandyn at Mon Sep 23 19:39:08 GMT 2024view raw

  1. # regexp list below is created from a file. I have simulated the list below.
  2. # Each elements might contain an replace arg at the end, separeted by space, in this case "replArg:\s".
  3. set cleanDef [list \
  4. {<[^>]*>} {^\s?DN\s(Direkt\s[\\-]|Debatt(?:\sRepliker)?\.)\s replArg:\s} \
  5. {^\s?SvD(:?\:s)?\s[Mm]orgonrapport:?\s} {^\s?Direkt\:\sLIVECHATT\:\s replArg2:\s} \
  6. {\s[-](\s[[:upper:]ÅÄÖ][^[:space:]]*){1,2}$} {\s\|\s.*}]
  7.  
  8. # example title to do "changes" to..
  9. set dirty "DN Direkt - hello there, how are you?"
  10.  
  11. foreach def $cleanDef {
  12.  
  13. # if an replace argument is included
  14. if {[llength $def] == "2"} {
  15. set dirty [regsub -all [lindex [split $def] 0] $dirty [lindex [split $def] 1]]
  16. set dirty [regsub -all "\\\\s" $dirty " "]
  17. puts $dirty
  18.  
  19. } else {
  20.  
  21. set dirty [regsub -all $def $dirty ""]
  22. puts $dirty
  23. }
  24.  
  25. }
  26.  
  27. puts "\nFinal\n$dirty"