检查string中包含http[s]链接

NSError*error;

NSString*regulaStr =@"\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?";

regulaStr =@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";

NSRegularExpression*regex = [NSRegularExpressionregularExpressionWithPattern:regulaStr

options:NSRegularExpressionCaseInsensitive

error:&error];

NSArray*arrayOfAllMatches = [regexmatchesInString:stringoptions:0range:NSMakeRange(0, [stringlength])];

NSString*substringForMatch;

for(NSTextCheckingResult*matchinarrayOfAllMatches)

{

substringForMatch = [stringsubstringWithRange:match.range];

//NSLog(@"substringForMatch");

}

returnsubstringForMatch;

你可能感兴趣的:(检查string中包含http[s]链接)