我编写了以下用于检测RAID类型的程序。当我运行以下脚本时,re
模块与字符串不匹配,并始终给我Raid Type not found
输出。
import subprocess
import re
RAIDTYPE = subprocess.Popen('lspci -mm |grep -i "RAID bus controller"', shell=True, stdout=subprocess.PIPE)
output=RAIDTYPE.communicate()[0]
matchObj = re.match(r'(.*) MegaRAID (.*?) .*', output, re.M|re.I)
matchObj1 = re.match(r'(.*) 3ware (.*?) .*', output, re.M|re.I)
if matchObj:
print("This is MegaRAID")
elif matchObj1:
print("This is 3Ware Raid")
else:
print("Raid Type not found")
答案 0 :(得分:0)
似乎正则表达式不正确。这应该起作用:
re.match(r'.*MegaRAID.*', output, re.M|re.I)