Q:

How to make a string as an optional to wait for it in an expect script?

The below script works in the case, where all three questions are being asked, but sometimes the Do you trust the above certificate [y|N] --> question is not asked by asadmin ... and so my expect fails.
Question
Is it possible to make the Do you trust the above certificate [y|N] --> question optional, so the expect script doesn't fails when this question in not asked?
#!/usr/bin/expect

set password [lindex $argv 0]

spawn asadmin --user admin change-admin-password
expect "password"
send "\n"
expect "password"
send "$password\n"
expect "password"
send "$password\n"
expect "Do you trust the above certificate \[y\|N\] -->"
send "y\n"
expect eof
exit

A:

set password [lindex $argv 0]

spawn asadmin --user admin change-admin-password

 # First time, when we see the password, we are simply typing 'return' key
expect "password"
send "\n"

expect { 
        "password"  { send "$password\n"; exp_continue }
        -ex "Do you trust the above certificate \[y|N] -->" {send "y\n";exp_continue}
        timeout { puts "Timeout happened." } 
        eof { exit }
 }

As you can see, exp_continue will help us in getting what you need. 
If expect sees password, it will send the password value. Notice the use of exp_continue in there.
It will cause the expect to run again. So, the expect will see the password twice and if suppose, expect sees the question, it will send 'y\n'. If it sees eof before, then script will exit.
Please note that I have kept the first expect statement with password separately outside. The reason being is nothing but the value we are sending is different for the first time alone. 
Also note the use of the -ex flag in the expect statement as below.
-ex "Do you trust the above certificate \[y|N] -->" {send "y\n";exp_continue}

It will make the expect to prevent any sort of special pattern matching. It is sufficient to escape the first square bracket alone.

