expect正则捕获返回结果
来源:互联网 发布:transmit mac 编辑:程序博客网 时间:2024/05/23 19:26
expect:
expect -re "([0-9]*)([a-zA-Z]*)"send_user "num is $expect_out(1,string), string is $expect_out(1,string)"
这里[0-9]*表示一个或多个数字,[a-zA-Z]*表示多个字母。()用于分组,它们分别存放在$expect_out(1,string)和$expect_out(2,string)中。
pexpect:python中的expect
child.expect("([0-9]*)([a-zA-Z]*)print "num is %s, string is %s" % (child.match.group(1),child.match.group(2))
注意,pexpect 匹配字符串是从sendline的命令开始算的, 而不是命令返回结果开始。
比如,我现在执行pgrep ssh0,它的返回是ssh0的pid,如果我的expect re用"(\d+)",最后output匹配的结果是0, 其中child.before = ‘pgrep ssh’,child.after = '0'
child.sendline (“pgrep shh0”) child.expect("(\d+)") output = child.match.group(1)
当换成child.expect("\r\n(\d+)\r\n")后就能正确的匹配到pid了。
- expect正则捕获返回结果
- expect获取返回值
- 正则捕获
- 返回单个匹配结果 正则(PHP代码函数)
- 返回所有匹配结果 正则(PHP代码函数)
- JavaScript—正则表达式匹配成功后的返回结果
- Android 捕获Activity 返回
- 正则表达式捕获分组
- 正则表达式捕获文本
- 正则表达式--非捕获
- perl 正则命名捕获
- Grok 正则捕获
- grok 正则捕获
- 正则的捕获
- 正则的捕获
- 正则的捕获
- 正则的捕获
- python 正则捕获
- android中MediaPlayer和SoundPool的声音管理
- ant build 出错Android build.xml renderscript doesn't support includepath
- 第 3 章 Python
- 店员每天电脑开机,或者有空余时间要经常检查部分(电脑部分)
- 2012年度工作总结
- expect正则捕获返回结果
- Discuz x2.5 后台邮件设置方法
- 收银员早班或者是晚班下班后,必须操作部分
- 收银必须要会操作部分
- 输出php传递给模板文件的普通变量及对象
- 用PDB库调试Python程序
- ACdream群原创群赛(2) A~F J 解题报告
- 编译android源码前的准备
- 认识店面桌面图标的作用和意义