我正在尝试在 Python 中创建一个正则表达式来捕获来自 winerror.h 和 ntstatus.h 的所有最后错误、HRESULT 和 NTSTATUS 定义:
例如,对于这段文字:
//
// MessageId: NTE_BAD_PROV_TYPE
//
// MessageText:
//
// Invalid provider type specified.
// More data is avaiable on bla bla.
//
#define NTE_BAD_PROV_TYPE _HRESULT_TYPEDEF_(0x80090014L)
我要捕捉:
('指定的提供商类型无效。bla bla 上有更多数据可用。',
'NTE_BAD_PROV_TYPE',
0x80090014)
同样适用于 ntstatus.h
:
//
// MessageId: STATUS_NOT_ALL_ASSIGNED
//
// MessageText:
//
// Indicates not all privileges or groups referenced are assigned to the caller.
// This allows, for example, all privileges to be disabled without having to know exactly which privileges are assigned.
//
#define STATUS_NOT_ALL_ASSIGNED ((NTSTATUS)0x00000106L)
最佳答案
我认为这已经足够接近了:
re.findall(r"(?<=// )(?:Message\w{2,4}:)? ?(.+)?\n", text)
+ list(re.search(r"(0x\d+)", text).groups())
['NTE_BAD_PROV_TYPE',
'',
'Invalid provider type specified.',
'More data is avaiable on bla bla.',
'0x80090014']
关于python - 使用正则表达式解析 winerror.h 和 ntstatus.h 状态/定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47181635/