我在我的iPhone应用程序上使用以下代码,从这里获取条带.html代码中的所有URL.
我只能提取第一个URL,但我需要一个包含所有 URL 的数组.我的NSArray没有为每个URL返回NSStrings,只返回对象描述.
如何arrayOfAllMatches以NSStrings的形式返回所有网址?
-(NSArray *)stripOutHttp:(NSString *)httpLine {
// Setup an NSError object to catch any failures
NSError *error = NULL;
// create the NSRegularExpression object and initialize it with a pattern
// the pattern will match any http or https url, with option case insensitive
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"http?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?" options:NSRegularExpressionCaseInsensitive error:&error];
// create an NSRange object using our regex object for the first match in the string httpline
NSRange rangeOfFirstMatch = [regex …Run Code Online (Sandbox Code Playgroud)