I need to match multi-line preprocessor instructions, such as:
#define max(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a : _b; })
The dot should match everyone #defineand last }), but I still can't figure out how to write a regex. I need it to work in Python using the "re" module.
#define
})
Can someone help me?
thank
This should do it:
r'(?m)^#define (?:.*\\\r?\n)*.*$'
(?:.*\\\r?\n)*matches zero or more lines ending with backslashes, then .*$matches the last line.
(?:.*\\\r?\n)*
.*$
I think something like this will work:
m = re.compile(r"^#define[\s\S]+?}\)*$", re.MULTILINE) matches = m.findall(your_string_here)
, '}', ')' .
I think that the solution may not work:
#define MACRO_ABC(abc, djhg) \ do { \ int i; \ /* * multi line comment */ \ (int)i; \ } while(0);
Source: https://habr.com/ru/post/1736475/More articles:ActiveDirectory DirectorySearcher: check if user is a member of a group - c #ASP.NET 4.0 Session Fixing Experiments - securityDouble click JavaScript blocking - javascriptDisplay values ββwith leading zeros - phpUsing NSUserDefaults how to save a key before launching an application - iphoneDependency Property in WPF / SilverLight - wpfASP.NET MVC, can a controller change the entered values? - asp.net-mvcHow do I dynamically scale my Google map? - google-mapswhat is the best free editor for xslt and mybe xsl: fo and xml? - xmldevelopment of a simple form - javaAll Articles