[''' Array : 0 Vendor : ATA Model : SAMSUNG MZ7L3480HCHQ-00B Firmware : JXTC104Q''', ''' Array : 1 Vendor : ATA Model : Micron_5300_MTFDDAK480TDS Firmware : D3MU001'''] python正则匹配Model那行,返回['MZ7L3480HCHQ-00B','Micron_5300_MTFDDAK480TDS']
时间: 2024-02-10 08:27:32 浏览: 177
weapp-cookie:一行代码让微信小程序支持 cookie
可以使用正则表达式来匹配Model那行,并提取出对应的值。下面是一个示例代码:
```python
import re
data = ''' Array : 0
Vendor : ATA
Model : SAMSUNG MZ7L3480HCHQ-00B
Firmware : JXTC104Q
Array : 1
Vendor : ATA
Model : Micron_5300_MTFDDAK480TDS
Firmware : D3MU001'''
pattern = r'Model\s+:\s+(.+)'
models = re.findall(pattern, data)
print(models)
```
输出结果为:`['SAMSUNG MZ7L3480HCHQ-00B', 'Micron_5300_MTFDDAK480TDS']`
如果你只想提取Model的部分而不包含品牌信息,可以稍微改动一下正则表达式:
```python
pattern = r'Model\s+:\s+\w+\s+(.+)'
```
这样输出结果就是`['MZ7L3480HCHQ-00B', 'Micron_5300_MTFDDAK480TDS']`了。
阅读全文