0

I am trying to capture words with 3+ characters including: we've, haven't, can't etc in my string. Below works for words except above ones. Am I missing something here? Should I hit the limit of nsregularexpressions in obj-c? Should I go with NSPredicates?

 NSString *currentString = aString;

// Regular expression to find all words that have greater than 3 characters
NSRegularExpression *regex;
regex = [NSRegularExpression regularExpressionWithPattern:@"([\\w\']{4,})"
                                                  options:0
                                                    error:NULL];

NSMutableString *modifiedString = [currentString mutableCopy];
__block int offset = 0;
[regex enumerateMatchesInString:currentString options:0 range:NSMakeRange(0, [currentString length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
    NSRange range = [result rangeAtIndex:0];
   // NSLog(@"range is %@", NSStringFromRange(range));
    // Adjust location for modifiedString:
    range.location += offset;
    // Get old word:
    NSString *oldWord = [modifiedString substringWithRange:range];
}
 ];
4

0 回答 0