I'm trying to detect any words between asterisks:
NSString *questionString = @"hello *world*";
NSMutableAttributedString *goodText = [[NSMutableAttributedString alloc] initWithString:questionString]; //should turn the word "world" blue
NSRange range = [questionString rangeOfString:@"\\b\\*(.+?)\\*\\b" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
DLog(@"found a word within asterisks - this never happens");
[goodText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
}
But I never get a positive result. What's wrong with the regex?