从NSString中提取URL

 1 NSString *src = @"<a href="http://weibo.com" rel="nofollow">新浪微博</a>"
2 NSRange r=[src rangeOfString:@"<a href"];
3 if (r.location!=NSNotFound) {
4
5 NSRange start=[src rangeOfString:@"<a href=\""];
6 if (start.location!=NSNotFound) {
7 int l=[src length];
8 NSRange fRange=NSMakeRange(start.location+start.length, l-start.length-start.location);
9 NSRange eRange=[src rangeOfString:@"\"" options:NSCaseInsensitiveSearch range:fRange];
10 if (eRange.location!=NSNotFound) {
11
12 r.location=start.location+start.length;
13 r.length=eRange.location-r.location;
14 NSString * sourceUrl=[src substringWithRange:r];
15
16 }
17
18 }
原文地址:https://www.cnblogs.com/woainilsr/p/2367992.html