查找子串

NSRegularExpressionCaseInsensitive :忽略大小写

NSString *superString = @"aBcdeAbc";
NSString *subString = @"ab";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:NSRegularExpressionCaseInsensitive error:nil];
NSArray *matches =  [regex matchesInString:superString options:0 range:NSMakeRange(0, superString.length)];
[matches enumerateObjectsUsingBlock:^(NSTextCheckingResult * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSRange range = obj.range;
        NSLog(@"range = %@, rangeString = %@",NSStringFromRange(range),[superString substringWithRange:range]);
}];

你可能感兴趣的:(查找子串)