【发布时间】:2016-09-06 23:48:09
【问题描述】:
我有一个来自日志的短语列表,我想使用以下正则表达式验证名称。 phrase 是有效的,但我仍然失败了。谁能告诉我这是什么问题?
非常感谢!
phrase = "ServerName.192.168.12.12.52915"
regex = re.compile("\bServerName\.\^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,5}$")
res = regex.match(phrase)
if test:
print "pass"
else:
print "fail"
【问题讨论】:
-
你的输入没有插入符号,你的模式有
\^。看here。您甚至不需要在模式的开头使用任何\b。 -
谢谢。很容易错过。