Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-24-2012, 03:04 PM   #1
Registered: Apr 2011
Location: Philadelphia
Posts: 160

Rep: Reputation: 3
Equivalent to Perl's "=~" Operator?

Hello All,

Alright, so this is driving me absolutely insane. I can't seem to find this ANYWHERE...
I've tried every combination and synonym I can think of for this trying to search Google.

What is the Expect/Tcl equivalent to Perl and Bash's "=~" operator, (i.e. the "contains" operator).
I'm trying to do an if statements to check if a line contains a specific string, and the only operators I could find anywhere for Expect are (==, !=, <=, >=, <, >)...

Anyone have any clue if it's possible to do a pattern match in an Expect Script's if statement?
Any thoughts would be much appreciated.

Thanks in Advance,
Old 07-24-2012, 09:53 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
I don't know enough about Tcl to say whether it includes a functional equivalent to Perl's =~ binding operator.

But you might be interested in this:
Old 07-24-2012, 10:16 PM   #3
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,238

Rep: Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405Reputation: 1405
I don't know tcl either but the Tcl Reference Manual page for strings says:

string first needleString haystackString ?startIndex?
Search haystackString for a sequence of characters that exactly match the characters in needleString. If found, return the index of the first character in the first such match within haystackString. If not found, return -1.
Old 07-25-2012, 09:21 AM   #4
Registered: Apr 2011
Location: Philadelphia
Posts: 160

Original Poster
Rep: Reputation: 3
Hey guys, thanks for your replies...

I came across what I was looking for last night.
Expect/Tcl doesn't exactly have a REGEX operator like Perl's "=~" operator but I did find this and it seems to do what I need.

Here's an example of the regexp command for Expect/Tcl in the If Statement below:
set myString "foo"

expect {
    -re ".*foo.*" {
            send "ls -l\r"
            # Loop through the previous send command's output line-by-line
            foreach line [split $expect_out(buffer) "\n"] {
                # If the current line contains $myString, then...
                if {[regexp ".*$myString.*" $line]} {
                        puts "FOUND WHAT I'M LOOKING FOR!"

Thanks Again,


expect, tcl

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: how to save an e-mail attachment on disk keeping the "&" character (no "%26"!!) d1s4st3r Programming 5 09-29-2010 10:30 PM
"Failed Dependency error" while installing RPM for "DateTime" perl modules giridhargopal.cj Linux - Newbie 7 11-19-2008 01:05 AM
Is there an "apt-get" equivalent of "yum list available"? geeeeky.girl Linux - General 3 07-20-2008 09:40 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 05:51 AM
Perl question concerning the "next" operator joesbox Programming 3 03-27-2005 09:59 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration