匹配 C 多行预处理器语句的正则表达式

Mar*_*tin 4 python regex

我需要的是匹配多行预处理器的语句,例如:

#define max(a,b) \
       ({ typeof (a) _a = (a); \
           typeof (b) _b = (b); \
         _a > _b ? _a : _b; })
Run Code Online (Sandbox Code Playgroud)

重点是匹配#define和 last之间的所有内容}),但我仍然不知道如何编写正则表达式。我需要它才能使用“re”模块在Python中工作。

有人可以帮我吗?

谢谢

Ala*_*ore 5

这应该可以做到:

r'(?m)^#define (?:.*\\\r?\n)*.*$'
Run Code Online (Sandbox Code Playgroud)

(?:.*\\\r?\n)*匹配零个或多个以反斜杠结尾的行,然后.*$匹配最后一行。