//组装一个字符串,把里面的网址解析出来NSString *urlString = @"sfdshttp://www.baidu.com";NSError *error;//http+:[^\\s]* 这是检测网址的正则表达式NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"http+:[^\\s]*" options:0 error:&error];if (regex != nil) {NSTextCheckingResult *firstMatch = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, [urlString length])];if (firstMatch) {NSRange resultRange = [firstMatch rangeAtIndex:0];//从urlString中截取数据NSString *result = [urlString substringWithRange:resultRange];NSLog(@"%@",result);}}
联系客服