美文网首页
查找子串

查找子串

作者: 田小北北 | 来源:发表于2022-03-01 14:55 被阅读0次
    NSRegularExpressionCaseInsensitive :忽略大小写
    
    NSString *superString = @"aBcdeAbc";
    NSString *subString = @"ab";
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:NSRegularExpressionCaseInsensitive error:nil];
    NSArray <NSTextCheckingResult *>*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]);
    }];
    

    相关文章

      网友评论

          本文标题:查找子串

          本文链接:https://www.haomeiwen.com/subject/ajgdrrtx.html