我正在尝试捕获包含3个以上字符的字词,其中包括:我们在字符串中输入,避免,等等。以下内容适用于上述词语。我在这里错过了什么吗?我应该在obj-c中达到nsregularexpressions的限制吗?我应该和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];
}
];