How to do lappend in a while loop using regexp
问题 when I am using the while loop to match a variable using regexp I want the matched variable to form a list by using lappend. The code is set file_name [open filename.txt r] set newlist [list] while {[gets $file_name line] >= 0} { regexp {cell \(\"(.*)\"} $line match cell_name if {[info exists cell_name] && $cell_name != ""} { puts "$cell_name" lappend $newlist $cell_name unset cell_name } } foreach item $newlist {puts $item} close $file_name The text which it is matching is like cell ("aabbcc