は、次の方法を使用することができます。
Swift4
let testString: String = "{\"timestamp\":1509507857555,\"profileId\":\"e58d7f751c7f498085a79a37bf22f20b\",\"profileName\":\"Rhidlor\",\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/1137b867b4a2fb593cf6d05d8210937cc78bc9e0558ad63d41cc8ec2f99e7d63\"}}}"
let pat = "http?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?"
let regex = try! NSRegularExpression(pattern: pat, options: [])
let matches = regex.matches(in: testString, options: [], range: NSRange(location: 0, length: LGSemiModalNavViewController.characters.count))
var matchedUrls = [String]()
for match in matches {
let url = (htmlSource as NSString).substring(with: match.range)
matchedUrls.append(url)
}
print(matchedUrls)
のObjective - C
NSString *testString = @"{\"timestamp\":1509507857555,\"profileId\":\"e58d7f751c7f498085a79a37bf22f20b\",\"profileName\":\"Rhidlor\",\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/1137b867b4a2fb593cf6d05d8210937cc78bc9e0558ad63d41cc8ec2f99e7d63\"}}}";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"http?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?" options:NSRegularExpressionCaseInsensitive error:&error];
NSArray *arrayOfAllMatches = [regex matchesInString:testString options:0 range:NSMakeRange(0, [testString length])];
NSMutableArray *arrayOfURLs = [NSMutableArray new];
for (NSTextCheckingResult *match in arrayOfAllMatches) {
NSString *substringForMatch = [testString substringWithRange:match.range];
NSLog(@"Extracted URL: %@", substringForMatch);
[arrayOfURLs addObject:substringForMatch];
}
NSLog(@"%@",arrayOfURLs);
これは私が探していたものです、助けてくれてありがとう! –