Posted to tcl by kbk at Sun Jul 11 20:46:03 GMT 2021view pretty

set s {
    This text contains "quoted strings"
    some of which contain "escaped \" characters"
    and even "escaped \\ characters"
}

set start 0
while {[regexp -indices -start $start {"([^"]|\\\"|\\\\)*"} $s result]} {
    lassign $result from to
    set matched [string range $s $from $to]
    puts "$from: $matched"
    set start [expr {$to+1}]
}