Last active
January 31, 2019 03:50
-
-
Save rickytan/66f70b5c8bcec22050562fb10a650f93 to your computer and use it in GitHub Desktop.
A Macro to generate regular expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef REGEXP | |
# define _regexp_stringify(x) #x | |
# define _regexp_stringify2(x) _regexp_stringify(x) | |
# define _regexp(...) ({ const char *str = _regexp_stringify2(# __VA_ARGS__); const size_t length = strlen(str); [[NSString alloc] initWithBytes:str + 1 length:length - 2 encoding:NSUTF8StringEncoding]; }) | |
# define REGEXP(...) [NSRegularExpression regularExpressionWithPattern:_regexp(__VA_ARGS__) options:0 error:NULL] | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment