美文网首页
检查string中包含http[s]链接

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

作者: MrLvlin | 来源:发表于2017-01-12 11:15 被阅读0次

    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]链接

          本文链接:https://www.haomeiwen.com/subject/imydbttx.html