除非我提供全文,否则正则表达式在 pywinauto 中不起作用
Regular expression not working in pywinauto unless I give full text
这是我正在使用的代码片段:
browserWin = application.Application()
browserWin.Start(<FirefoxPath>)
# This starts the Firefox browser.
browserWin.Window_(title_re="\.* Firefox \.*")
如果我使用表达式:“.* Mozilla Firefox Start Page .*”,它会起作用。但是,如果我只使用部分文本,它就不起作用。
我做错了什么?
请参阅 pywinauto 源代码的摘录:
title_regex = re.compile(title_re)
def _title_match(w):
t = handleprops.text(w)
if t is not None:
return title_regex.match(t)
return False
return title_regex.match(t)
行表示将正则表达式传递给 re.match
方法,因此,正则表达式模式锚定在字符串开头。
要进行部分匹配,您需要以 .*
开始模式:".* FireFox "
.
用“\”转义.
意味着真正的点符号应该在文本的开头。只需删除“\”。
这是我正在使用的代码片段:
browserWin = application.Application()
browserWin.Start(<FirefoxPath>)
# This starts the Firefox browser.
browserWin.Window_(title_re="\.* Firefox \.*")
如果我使用表达式:“.* Mozilla Firefox Start Page .*”,它会起作用。但是,如果我只使用部分文本,它就不起作用。
我做错了什么?
请参阅 pywinauto 源代码的摘录:
title_regex = re.compile(title_re)
def _title_match(w):
t = handleprops.text(w)
if t is not None:
return title_regex.match(t)
return False
return title_regex.match(t)
行表示将正则表达式传递给 re.match
方法,因此,正则表达式模式锚定在字符串开头。
要进行部分匹配,您需要以 .*
开始模式:".* FireFox "
.
用“\”转义.
意味着真正的点符号应该在文本的开头。只需删除“\”。