我是正则表达式的新手。什么是正则表达式找到所有" DataKeyNames"其次是","串?我试图找到我们所拥有的所有文本" DataKeyNames"其次是","在各种文件中。
{
"Modules": {
"2": {
"World-Wide-Name(s) (WWN)": "20:01:54:7f:ee:df:88:f8 to 20:30:54:7f:ee:df:88:f8",
"Module-Type": "1/2/4/8 Gbps FC/Supervisor-3",
"Ports": "48",
"Sw": "6.2(17)",
"Hw": "1.1",
"Model": "DS-C9148-K9-SUP",
"Status": "active *",
"Serial-Num": "JAF1736AXXX",
"MAC-Address(es)": "c0-8c-60-65-82-ec to c0-8c-60-65-82-ef",
"Mod": "2"
},
"1": {
"World-Wide-Name(s) (WWN)": "20:01:54:7f:ee:df:88:f8 to 20:30:54:7f:ee:df:88:f8",
"Module-Type": "1/2/4/8 Gbps FC/Supervisor-3",
"Ports": "48",
"Sw": "6.2(17)",
"Hw": "1.1",
"Model": "DS-C9148-K9-SUP",
"Status": "active *",
"Serial-Num": "JAF1736ALLM",
"MAC-Address(es)": "c0-8c-60-65-82-dc to c0-8c-60-65-82-df",
"Mod": "1"
}
},
"Xbars": {
"1": {
"Module-Type": "Fabric 1",
"Ports": "0",
"Sw": "NA",
"Hw": "1.0",
"Model": "ABC",
"Status": "ok",
"Xbar": "1"
}
}
}
答案 0 :(得分:0)
我不知道你想找到什么但是:
1)如果你想'AppRevObjId'只使用这个:
import re
s = 'AppRevObjId, AsmtIdsOnHold'
re.findall('([^\s]+),' , s)
输出:
['AppRevObjId']
2)如果你只想要'AsmtIdsOnHold':
re.findall(',\s([^\s]+)' , s) # or-> re.findall(', ([^\s]+)' , s)
3)如果你想要两个:
re.findall('([^\s]+), ([^\s]+)' , s) # or-> re.findall('([^\s]+),\s([^\s]+)' , s)
[('AppRevObjId', 'AsmtIdsOnHold')]
输出:
[('AppRevObjId', 'AsmtIdsOnHold')]
所以请详细解释或报告错误以修复代码中的问题和错误