Python代码,用于从字符串中提取具有value的相似关键字



获取的命令输出字符串如下....

Key_word = {"Devices on the system.

Device description: device-1
Device status: Healthy
Handle: 0xFF00
Device description: device-2
Device status: Healthy
Handle: 0xC00A

Device description: device-3
Device status: Healthy
Handle: 0xDD00"}

要求输出:我希望Python代码提取如下列表

{'Handle: 0xFF00', Handle: 0xC00A', Handle: 0xDD00}

下面的代码列出了所需的输出.....

import re
key =  'Handle: 0x[0-9a-fA-F]+'
final_list = []
final_list = re.findall(key, str(input_string))
print(final_list)

最新更新