iOS - 获取文段中的链接

+ (NSString *)getNewSubStoreNameByRegularExpression:(NSString *)storeName{
    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(http|https|ftp)://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?([:a-zA-Z0-9\\-\\._?\\,'\\+&$*%$#/=~])*" options:0 error:&error];
    NSArray *arrayOfAllMatches = [regex matchesInString:storeName options:0 range:NSMakeRange(0, [storeName length])];
    if (arrayOfAllMatches && arrayOfAllMatches.count > 0 ) {
        NSTextCheckingResult *oB = arrayOfAllMatches[0];
        NSString *currentUrlStr = [storeName substringWithRange:oB.range];
        return currentUrlStr;
    }
    return storeName;
}

你可能感兴趣的:(iOS - 获取文段中的链接)