Noob Expect Scripting Question

I'm having some difficulty with convincing Expect to do what I need..
I have a loop that waits for input, a specific phrase of text followed by a single word. I need Expect to capture that word following the specific phrase. It should then store the word in a variable.
I'm fairly sure it's simple, but for some reason, the solution is eluding me. Any help would be appreciated.

What do you have so far?

I have literally nothing as far as this function. This is a chat bot for a hopelessly obscure TTY-based chat system. Right now, it logs in, idles, and responds to specific commands as part of a loop. So far, I haven't had to make any of those responses depend on a particular part of the command. This function will be the instruction to move the bot to another room. If this were IRC, it'd be so much easier. :cool:
Essentially, the bot will see as text in the room "kimiko, go to " (the bot's account name is kimiko), and the word immediately following the space after 'to' will be the room name. I want the script to use "kimiko, go to " as the trigger (expect "kimiko, go to ") and the action to be to capture the following word.

This is part of the main loop. I left some of the functions in so you can see how it operates. The changing room thing basically has me scratching my head completely. I know how to make it look for the trigger phrase. I don't know how to initiate capturing the next word after the trigger phrase.

while {$Exit != 1 } {
# Temporary simulated commands/responses
expect {
# Greeting, response
    "hai kimiko"    {
        send "\r"
        send "o hai\r"
    }
# Change rooms
    "kimiko, go to"    {
        #Capture the word following 'kimiko, go to ' and store in GoRoom
        send "g" # Initiates room change
        send "$GoRoom\r" #Dumps GoRoom variable into change room command
     }
# Approval of all 'kick' actions against user 'magizian'
    "needs approval to kick magizian"    {
        send "k"
        send "approve\r"
    }
# Exit command�
    "kimiko, you may go now"    {
# Sets Exit variable to 1 to cause loop to exit
        set Exit "1"
        send "\r"
        send "bai\r"
    }
}

# Close brace for end of 'while' loop
}


This might help:

$ echo "kimiko, go to work" | ./kimiko.sh
Going to: work

$ cat kimiko.sh
#!/usr/bin/expect -f
expect {
   -re "kimiko, go to (.*)\n" {
       set output $expect_out(1,string)
       send "Going to: $output\n"
   }
}
expect eof

That looks like something I can work with. I'm going to have to wedge that in and see how it acts before I'm sure I understand it. :eek:
I'll get back with you here in a bit if it works.

---------- Post updated at 03:45 PM ---------- Previous update was at 03:31 PM ----------

Ok so I modified the function to suit the weird vi-like command/talk mode structure of the chat app.. here's what it looks like now.

# Change rooms
    "kimiko, go to (.*)\n" {
       set TargetRoom $expect_out(1,string)
       send "\r"
       send "going to $TargetRoom\r"
       send "g"
       send "$TargetRoom\r"
     }

I tested it out, and the bot just ignores the text as if it's not one of the strings it looks for.

Don't forget to put the -re in front of your string, this tells the expect command your using a regular expression (vi-like command/talk)

DERP
That did it. It works beautifully now. Thanks so much. I *should* be able to adapt that to whatever I need for other functions.

*edit*
I'm going to have to work on learning regular expressions to provide some input validation. Don't suppose anyone would like to show me how to make that accept upper/lowercase letters only, would they?