使用正则将System Manufacturer To be filled by O.E.M. System Product Name中提取出{''System Manufacturer":"To be filled by O.E.M."}
时间: 2024-04-13 17:28:13 浏览: 123
要将 "System Manufacturer To be filled by O.E.M. System Product Name" 中的内容提取为 `{'System Manufacturer': 'To be filled by O.E.M.'}`,可以使用以下正则表达式和代码:
```python
import re
text = "System Manufacturer To be filled by O.E.M. System Product Name"
pattern = r"(?P<manufacturer>.*?)\s+(?P<product>To be filled by O\.E\.M\.)"
result = re.search(pattern, text)
if result:
extracted_text = {
'System Manufacturer': result.group('manufacturer'),
'System Product Name': result.group('product')
}
print(extracted_text)
else:
print("No match found.")
```
这段代码将会输出 `{'System Manufacturer': 'To be filled by O.E.M.', 'System Product Name': 'To be filled by O.E.M.'}`。在正则表达式中,使用了命名捕获组 `(?P<manufacturer>.*?)` 和 `(?P<product>To be filled by O\.E\.M\.)` 来匹配相应的内容,并在结果中以字典的形式进行保存。记得根据你的需求修改文本内容和键的名称。
阅读全文