MWFeedParser删除嵌入式媒体URL - iOS

时间:2013-01-25 02:42:25

标签: ios objective-c rss

我有以下网址的网页来源信息,如下所示: http://feeds.feedburner.com/thecarconnection/porsche

 <description>&lt;img src='http://images.thecarconnection.com/tmb/2013-porsche-panamera-platinum-edition_100405984_t.gif'/&gt; Best known for its legendary two-door sports cars, Porsche has branched out to the SUV and sedan fields in recent years. The company's first four-door car, the Porsche Panamera, has set tongues wagging and hearts yearning with its blend of unconventional style and blazing performance. While the Panamera range spans a broad scope, it competes...&lt;img src="http://feeds.feedburner.com/~r/thecarconnection/porsche/~4/_LggPvmEzJ4" height="1" width="1"/&gt;</description>

我想从说明中删除'img src ='http://images.thecarconnection.com/tmb/2013-porsche-panamera-platinum-edition_100405984_t.gif''链接。我正在使用MWFeedParser作为描述的一部分解析URL。有关删除描述标记内链接的方法的任何建议吗?

1 个答案:

答案 0 :(得分:1)

您可以使用NSRegularExpression

尝试使用此代码段
NSString *description = ...;
NSError *error = NULL;

NSRegularExpression *regex = [NSRegularExpression
        regularExpressionWithPattern:@"\\&lt;img src='[^']*' */\\&gt;"
        options:NSRegularExpressionCaseInsensitive error:&error];

NSString *modifiedDescription = [regex stringByReplacingMatchesInString:description
           options:0
           range:NSMakeRange(0, [description length])
           withTemplate:@""];