这是我在带有emoji的消息列中收到的JSON:
<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>发布于 2015-09-09 06:07:47
NSString *htmslStr=@"<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:htmslStr
options:0
range:NSMakeRange(0, [htmslStr length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSString *img = [htmslStr substringWithRange:[result rangeAtIndex:2]];
NSURL *candidateURL = [NSURL URLWithString:img];
if (candidateURL && candidateURL.scheme && candidateURL.host)
{
NSLog(@"img src %@",img);
}
}];最后的结果是

https://stackoverflow.com/questions/32471760
复制相似问题