iOS - 获取中的scr图片地址

示例:
输出:
[图片地址1,图片地址2]


- (NSArray *)filterImageUrlFromHTML:(NSString *)html
{
    if (html == nil) {
        return nil;
    }
    NSString *dd = @"|>";
    NSMutableArray *resultArray = [NSMutableArray array];
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:dd options:NSRegularExpressionCaseInsensitive error:nil];
    
    NSArray *result = [regex matchesInString:html options:NSMatchingReportCompletion range:NSMakeRange(0, html.length)];
        
        for (NSTextCheckingResult *item in result) {
            NSString *imgHtml = [html substringWithRange:[item rangeAtIndex:0]];
            
            NSArray *tmpArray = nil;
            if ([imgHtml rangeOfString:@"src=\""].location != NSNotFound) {
                tmpArray = [imgHtml componentsSeparatedByString:@"src=\""];
            } else if ([imgHtml rangeOfString:@"src="].location != NSNotFound) {
                tmpArray = [imgHtml componentsSeparatedByString:@"src="];
            }
            
            if (tmpArray.count >= 2) {
                NSString *src = tmpArray[1];
              src = [src stringByReplacingOccurrencesOfString:@"/>" withString:@""];
              src = [src stringByReplacingOccurrencesOfString:@">" withString:@""];
                [resultArray addObject:src];
            }
        }
    return resultArray;
}

你可能感兴趣的:(iOS - 获取中的scr图片地址)