user707549
user707549

Reputation:

The meaning of the regular expression in TCL/EXPECT

I read a tcl test script, it uses EXPECT. some of the code is:

expect ".*hello.*yes.*morning.*"

The "*" wild card is matching everything, but what about the "." in front of it? what does this mean? what kind of pattern wanted to be matched?

Upvotes: 3

Views: 4317

Answers (3)

glenn jackman
glenn jackman

Reputation: 247162

Note that the expect command's default matching style is -glob, so those dots are in fact literal dots. Help with glob-style matching can be found in the string match documentation.

If you want your pattern to be considered as a regular expression, you have to say:

expect -re ".*hello.*yes.*morning.*"

Upvotes: 6

Herbert Sitz
Herbert Sitz

Reputation: 22266

The * is not a wildcard in regular expressions. You're thinking of shell operations with filename wildcards, but that's not how * works in regular expressions. Totally different animals. In your regex it's the . that matches any character, then the * that says 'match 0 or more of the preceding character.

Here's some info on regexes: http://www.regular-expressions.info/tutorial.html

and here's page directly addressing the confusion regex newbies may have between regular expressions and shell filename-matching patterns:

http://docstore.mik.ua/orelly/unix3/upt/ch32_02.htm

Upvotes: 1

KillianDS
KillianDS

Reputation: 17196

The * is not a wildcard in regular expressions, . is, the * after . means 0 or more occurances of the previous character/character class. So here it means: 0 or more occurences of any sign. Also note that depending on regex options, . often does not include newlines.

Upvotes: 3

Related Questions