Try this: expect to see 6 digits as a whole word
send "date +%d%m%y\r" ;# typically we use \r to "hit enter"
expect -re {\m(\d{6})\M}
set date1 "$expect_out(1,string)"
puts "$date1"
expect "#"
More generally, to select the text between the first line (the command) and the last line (the prompt), you can do:
lassign [regexp -inline {.*?\n(.*)\r\n#} $expect_out(buffer)] _ date1
where _
is a throw-away variable that will hold the entire matching text of the regex, and date1
will hold only the captured text.
See https://tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm for Tcl regex syntax.
Without lassign
, you could write
regexp {.*?\n(.*)\r\n#} $expect_out(buffer) _ date1