Expect regex number pattern Expect regex number pattern unix unix

Expect regex number pattern


I could resolve the problem:

#!/usr/bin/expect -fset timeout 3spawn bashsend "echo 0\n"expect -re "(\\d+)" {    set result $expect_out(1,string)}if { $result == 0 } {    send_user "\nzero\n";} else {    send_user "\nnumber\n";}send "exit\n"


Had a quick look at expect's documentation:

However, because expect is not line oriented, these characters match the beginning and end of the data (as opposed to lines) currently in the expect matching buffer.

Your regex should take into account the fact that you have line breaks.

If your data is 0\n, then you can use "^0\n$".


Try using word boundaries: \b0\b