iOS - 获取文段中的链接
2019-08-27 本文已影响0人
HanZhiZzzzz
+ (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;
}