Version 2 of Extract Numbers From a String

Updated 2022-10-02 10:52:29 by pooryorick

WJG 1022-10-01: A quick snippet on extracting a list of numbers from a string.

proc extractNumbers {str} {
        set res ""
        foreach c [split $str ""] {
                if { [string is integer $c] } {
                        set a 1
                        append res $c
                } elseif { $c eq "," || $c eq "." } {
                        if {$a} { append res $c }
                } else {
                        set a 0
                        append res " "
                }
        }
        return [string trim $res]
}

pyk 2022-10-02: What about numbers like "this .13 here?".