【发布时间】:2018-07-31 19:52:33
【问题描述】:
所以我有以下代码:
cus_str = "show configuration " #intiate router command string variable
with open(var) as config_file: #open file
for line in config_file: #line by line reading of file
if '"xe-" + #anynumber + "/" #anynumber + "/" + #anynumber' in line:
line = line.replace('\n' , '').replace('"' , '').replace(']' , '') #removes all extra characters
i = "| except " + (line.split("cust ", 1)[1]) + " " #split the line and save last index (cust name)
cus_str+=i #append to string
config_file.close()
行:if '"xe-" + #anynumber + "/" #anynumber + "/" + #anynumber' in line: 这就是我在语法方面苦苦挣扎的地方。
我正在查看文件中的一行是否包含以下字符串:“xe-number/number/number”(例如:“xe-6/1/10”)。它将始终具有这种格式,但数字会改变。我会使用什么样的语法来最有效地做到这一点。
谢谢!
【问题讨论】:
-
使用python的正则表达式模块
re:docs.python.org/3/library/re.html
标签: python regex string digits