Objective c 捕获单词中包含单引号的字符串
我正在尝试捕获字符串中包含3个以上字符的单词,包括:wehave、have、cannot等。除上面的词外,下面的词适用于其他词。我是不是遗漏了什么?我是否应该达到obj-c中nsregularexpressions的限制?我应该和NSPredicates一起去吗Objective c 捕获单词中包含单引号的字符串,objective-c,Objective C,我正在尝试捕获字符串中包含3个以上字符的单词,包括:wehave、have、cannot等。除上面的词外,下面的词适用于其他词。我是不是遗漏了什么?我是否应该达到obj-c中nsregularexpressions的限制?我应该和NSPredicates一起去吗 NSString *currentString = aString; // Regular expression to find all words that have greater than 3 characters NSReg
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];
}
];
你好,ilteris,你能解释一下你面临的问题吗?在我看来,这种模式对那些字符串很有效。你能举一个实际输出和预期输出不适合你的例子吗?可能是勾号、反勾号、unicode勾号等之间的区别,请参阅