我正在尝试编写一个python脚本的登录例程。在这样做的时候,我发现需要在整个词的基础上模式匹配凭证。我曾试图RegEx这个,但由于我不清楚的原因,这是失败的,但我希望这里的人很明显。代码和输出:Python RegEx与字边界
import re
authentry = "testusertestpass"
username = "testuser"
password = "testpass"
combo = "r\'\\b"+username + password + "\\b\'"
testcred = re.search(combo, authentry)
print combo
print authentry
print testcred
r'\btestusertestpass\b'
testusertestpass
None
,会出现我正则表达式的测试,至少对我来说,要正确格式化,而应该是对测试字符串直接匹配,但并非如此。有任何想法吗?非常感谢任何见解!
'R '\ B' +用户名+密码+ R'\ b'''r'前一个字符串文字意味着原始字符串的文本,这具有稍微不同的解析规则。 – nhahtdh 2014-11-21 08:43:52