我正在尝试解析/etc/mtab
但排除/boot
. 我认为也许非捕获组将是要走的路,但它并没有像我预期的那样工作。这是我构造的正则表达式:
proc = subprocess.Popen(["ssh", server, "cat", mtab],stdout = subprocess.PIPE)
for line in proc.stdout:
fsMatch = re.search(r'([\w/:]+) (/([\w/:-]+)|(?:boot)) (nfs|ext3)', line)
if fsMatch:
print fsMatch.group(1,2,4)
输出:
('/dev/sda1', '/boot', 'ext3')
('/dev/mapper/foo1', '/export/foo1', 'ext3')
('/dev/mapper/foo2', '/export/foo2', 'ext3')
('/dev/mapper/foo3', '/export/foo3', 'ext3')
('/dev/mapper/foo4', '/export/foo4', 'ext3')
('/dev/mapper/foo5', '/export/foo5', 'ext3')
('servernfs:/install', '/mnt', 'nfs')
我非常有信心这|
是错误的(显然更多是错误的),但遇到了障碍。
我正在寻找所有匹配项,/[\w/:-]+
但排除匹配项/boot
建议?