python - 如何在 tn.read_until() 中包含正则表达式?

标签 python regex telnet telnetlib

import telnetlib
tn = telnetlib.Telnet(IP)
tn.read_until("abcd login: ") --> This is only to match a particular pattern

tn.read_until() 中可以包含通用模式吗? 例如:提示符可以是 "xyz login: ", "abcd login: " etc

在正则表达式中,我们使用 re.match('(.*)login: ',prompt) 。但我不这么认为,这在 tn.read_until() 中有效,因为它期望的参数本身就是一个模式。有什么办法可以处理吗?

最佳答案

Telnet.expect接受正则表达式列表:

tn.expect([r"\w+ login: "])

关于python - 如何在 tn.read_until() 中包含正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27824001/

相关文章:

Python:将向量列表乘以矩阵列表作为单个矩阵运算

python - 匹配字符串中所有工作日名称的正则表达式

http - 从 Telnet 发送 http GET 命令

python - 如何逐行打印 telnet 响应?

java - 用正斜杠替换反斜杠

c# - Telnet 响应在 ~50 个字符后中间包含\r\n

python - ObjectPath: "in"运算符有问题

python - 如何让 LED 在 Google Assistant 监听时亮起?

python - 使用 Pytorch 为神经机器翻译加载巨大的文本文件

c# - 正则表达式: Getting everything except certain matching strings