Help in parsing expect command's output and remove new lines EXPECT scripting

I am new to expect scripting.

expect "# " {send "hostname -i\r"}
expect {
    -re "\r(.*)#" {set addr1 $expect_out(1,string)}
}

addr1 prints -

hostname -i
111.22.33.444

How do i get just 111.22.33.444 without any trailing new lines?

Thanks in advance

Your RE is matching the local echo of hostname -i\r sent earlier. Try this RE .*\r\n(.*)\r\n#

For example:

set timeout 3
log_user 0
expect "# " {send "hostname -i\r"}
expect {
   -re ".*\r\n(.*)\r\n# " {set addr1 $expect_out(1,string)}
   timeout { puts "Timeout looking for TCP/IP address\n"; }
}
send "exit\r"

puts "TCP/IP address is: $addr1"