This is only to match a...">

How do I enable regex in tn.read_until ()?

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

      

Can a generic template be included in tn.read_until()

? Ex: the invitation can be "xyz login: " , "abcd login: "

, etc.

In regex, we use re.match('(.*)login: ',prompt)

. But I don't think so it works in tn.read_until()

, because the parameter it expects itself is a template. Is there a way to handle this?

+3


source to share


1 answer


Telnet.expect

accepts a list of regular expressions:



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

      

+3


source







All Articles