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">& ...
随机推荐
- LA 3521 Joseph's Problem
题意:给你正整数n和k,然后计算从i到n k%i的和: 思路:如果n小于1000000,直接暴力计算,然后大于1000000的情况,然后在讨论n和k的大小,根据k%i的情况,你会发现规律,是多个等差数 ...
- github上值得研究的项目和人
https://github.com/Dax89?tab=repositories https://github.com/stars/gabrielcorado https://github.com/ ...
- 我的VSTO之路(四):深入介绍Word开发
原文:我的VSTO之路(四):深入介绍Word开发 在上一篇文章中,我介绍了Word的对象模型和一些基本开发技巧.为了更好的介绍Word插件开发,我为本文制作了一个Word书签的增强版,具体功能是让用 ...
- python operator模块
官网:https://docs.python.org/3.4/library/operator.html http://pymotw.com/2/operator/
- Poetize6: Acting Cute
3042: Acting Cute Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 59 Solved: 36[Submit][Status] Des ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- server 2008 ftp 环境重点说明
最近 在弄ftp 环境,但是 到server 2008 r2 这个系统之后,按照之前的方法 不行了 具体情况如下 利用本机 资源管理器 访问不了,根本不出现 登录框 提示 然后 到ftp 站点 ...
- margin:-75px的理解及妙用——纯CSS制作水平/垂直都居中短边为50px/长边为150px的红色十字架
有这么一个题目: 使用重构的方式制作出一个如下图的水平.垂直都居中短边为50px,长边为150px的红色十字架. 要求只使用2个div完成 答案: <!DOCTYPE html PUBLIC & ...
- CodeForces 588B
题目链接 : http://codeforces.com/problemset/problem/588/B 题目大意: 这个题目的意思就是找出一个数中的因子,这个因子满足以下条件: 1.此数的因子没有 ...
- VMware宿主机和虚拟机的网络连接问题
今天在win8上装了个vmware虚拟机,却发现一个vmware workstation宿主机ping不通centos虚拟机,宿主机和centos虚拟机都可以正常上网. 问题描述:今天在vmware ...