开发者

The meaning of the regular expression in TCL/EXPECT

I read a tcl te开发者_如何学JAVAst 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?


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.*"


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜