iOS中使用正则表达式去掉HTML中的标签元素获得纯文本的方法
content是根据网址获得的网页源码字符串
- (NSString *)changeToString:(NSString *)content
{
NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n"
options:0
error:nil];
content = [regularExpretion stringByReplacingMatchesInString:content options:NSMatchingReportProgress range:NSMakeRange(0, content.length) withTemplate:@"-"]; // 替换所有html和换行匹配元素为"-"
regularExpretion = [NSRegularExpression regularExpressionWithPattern:@"-{1,}" options:0 error:nil] ;
content = [regularExpretion stringByReplacingMatchesInString:content options:NSMatchingReportProgress range:NSMakeRange(0, content.length) withTemplate:@"-"]; // 把多个"-"匹配为一个"-"
// 根据"-"分割到数组
NSArray *arr=[NSArray array];
content = [NSString stringWithString:content];
arr = [content componentsSeparatedByString:@"-"];
NSMutableArray *marr=[NSMutableArray arrayWithArray:arr];
[marr removeObject:@""];
NSMutableString *string = [[NSMutableString alloc] init];
for (int i = 0; i < arr.count; i++) {
[string appendString:[NSString stringWithFormat:@"%@",arr[i]]];
}
return string;
}
iOS中使用正则表达式去掉HTML中的标签元素获得纯文本的方法的更多相关文章
- C#用正则表达式去掉Html中的script脚本和html标签
原文 C#用正则表达式去掉Html中的script脚本和html标签 /// <summary> /// 用正则表达式去掉Html中的script脚本和html标签 ...
- C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
/// 去掉字符串中的数字 public static string RemoveNumber(string key) { ...
- C# 使用正则表达式去掉字符串中的数字
/// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...
- C# .net 使用正则表达式去掉字符串中的数字
/// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...
- C#中使用 正则表达式 替换img中src路径但保留图片名
text = Regex.Replace(text, @"(?i)(?<=<img\b[^>]*?src=\s*(['""]?))([^'"& ...
- 在Python中使用正则表达式去掉字符串里的html标签
有时候会获得一些带html标签的字符串,需要把html标签去掉,获得干净的字符串,这时候可以使用正则表达式. 代码如下: import re htmeString = '''<ul id=&qu ...
- 【转】C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
源地址:http://www.cnblogs.com/94cool/p/4332957.html
- Java中使用正则表达式获取网页中所有图片的路径
public static List<String> getImageSrc(String htmlCode) { List<String> imageSrcList = ne ...
- 过滤eWebeditor等富文本中html标签,获得纯文本信息
/// <summary> /// 过滤html标签 /// </summary> /// <param name="Htmlstring">& ...
随机推荐
- nosql db and javascript performance
http://blog.csdn.net/yiqijinbu/article/details/9053467 http://blog.nosqlfan.com/tags/javascript http ...
- 线性链表的双向链表——java实现
.线性表链式存储结构:将采用一组地址的任意的存储单元存放线性表中的数据元素. 链表又可分为: 单链表:每个节点只保留一个引用,该引用指向当前节点的下一个节点,没有引用指向头结点,尾节点的next引用为 ...
- -_-#【Node】Express 400 Error: ENOENT, open
Express 400 Error: ENOENT, open cd alleatisland, node app来启动
- wpa_cli 连接 wifi
转自:http://hi.baidu.com/yyangjjun/item/9dfe8e175439fc7a1009b5ba 1: run wpa_supplicant first use the ...
- 字符串(多串后缀自动机):HDU 4436 str2int
str2int Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- Evaluate Reverse Polish Notation——LeetCode
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- FZYZOJ-1569 喝水
P1569 -- 喝水 时间限制:2000MS 内存限制:131072KB 状态:Accepted 标签: 无 无 无 Description GH的N个妹子要喝水, ...
- 在pcDuino上刷了AndDroid,Ubuntu,XBMC
一.Android.Ubuntu.XBMC播放高清视频得比较 1.Andrioid上播放1080P 无压力,硬件解码 2.Ubuntu上用Mplayer播放视频会很卡,可能是没有硬解的原因 3.Ubu ...
- python-类和对象(属性、方法)的动态绑定
动态绑定 # coding=utf-8 ''' 当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性 ''' from types im ...
- maven打一个可执行的jar包
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-depen ...