(1)#话题#
+ (NSRegularExpression *)regexTopic {
staticNSRegularExpression *regex;
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// #[^#]+# // #[^@#]+?# 话题
regex = [NSRegularExpression regularExpressionWithPattern:@"#([^@]+?)#"options:kNilOptions error:NULL];
});
returnregex;
}
(2)URL
#define TTRegexHttp @"([hH]ttp[s]{0,1})://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\-~!@#$%^&*+?:_/=<>.',;]*)?"
+ (NSRegularExpression *)regexURL {
staticNSRegularExpression *regex;
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
regex = [NSRegularExpression regularExpressionWithPattern:TTRegexHttp options:kNilOptions error:NULL];
});
returnregex;
}
(3)表情
+ (NSRegularExpression *)regexEmoticon {
staticNSRegularExpression *regex;
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
regex = [NSRegularExpression regularExpressionWithPattern:@"\\[/[^ \\[\\]]+?\\]"options:kNilOptions error:NULL];
});
returnregex;
}