美文网首页
找出字符串中的网址

找出字符串中的网址

作者: 伏特加 | 来源:发表于2016-05-07 15:11 被阅读43次
NSString *regulaStr = @"\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?";
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];
    NSArray *arrayOfAllMatches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];

    for (NSTextCheckingResult *match in arrayOfAllMatches)
    {
        NSString* substringForMatch = [string substringWithRange:match.range];
        NSLog(@"substringForMatch%@",substringForMatch);
    }

相关文章

网友评论

      本文标题:找出字符串中的网址

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