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;
网友评论