python - 使用正则表达式解析 winerror.h 和 ntstatus.h 状态/定义

标签 python c regex windows header

我正在尝试在 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/

相关文章:

javascript - 如何使用jquery删除特殊字符前的逗号

正则表达式捕获 : word {word} word

regex - 如何在vim中获取两个命令之间的字符串

python - 是否可以使用 XPATH 和 Selenium 从 Python 中的特定 div 开始计数?

python - 如何在 pandas 数据框中使用 if-else

c - scanf 验证用户输入

c++ - 来自变量的 Makefile : select files by extension,

python - 如何使用python从目录中删除文件

Python - 查找字符串列表中不重复的字符

c - memcpy 别名 int 到 char 产生 UB?