oc 正则图片<img /> 标签
-(NSString *)getImageAttributeValue:(NSString *)content attributeKey:(NSString *)key {
NSString *regexString = [NSString stringWithFormat:@"%@=\\\"(.*?)\\\"", key];
NSRange range = [content rangeOfString:regexString options:NSRegularExpressionSearch];
if (range.location != NSNotFound) {
return [[content substringWithRange:range] componentsSeparatedByString:@"\""][1];
} else {
return nil;
}
}
-(NSString *)filterFormularCodeTag:(NSMutableString *)htmlString
{
NSString *content = htmlString;
NSString *regexString = [NSString stringWithFormat:@"<img(.*?)code=(.*?)[^>]*?>"];
NSError *error = nil;
NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:regexString options:NSRegularExpressionCaseInsensitive error:&error];
NSArray *resultArray = [regular matchesInString:htmlString options:0 range:NSMakeRange(0, [htmlString length])];
for (NSTextCheckingResult *result in resultArray)
{
NSString *subString = [htmlString substringWithRange:result.range];
NSString *codeContent = [self getImageAttributeValue:subString attributeKey:@"code"];
content = [content stringByReplacingOccurrencesOfString:subString withString:codeContent];
}
return content;
}
oc 正则图片<img /> 标签的更多相关文章
- C#正则过滤HTML标签并保留指定标签的方法
本文实例讲述了C#正则过滤html标签并保留指定标签的方法.分享给大家供大家参考,具体如下: 这边主要看到一个过滤的功能: public static string FilterHtmlTag(str ...
- Python3正则去掉HTML标签
Python3正则去掉HTML标签 1.引用一段代码 import re html = '<pre class="line mt-10 q-content" accuse=& ...
- Python图形编程探索系列-04-网上图片与标签组件的结合
跳转到自己的博客 任务设定 任务:从网上找到一张图片,然后将其显示在标签上? 网上图片网站:http://pic.58pic.com/58pic/17/56/38/52w58PICtER_1024.j ...
- 能够附加图片的标签控件iOS项目源码
这个源码案例是能够附加图片的标签控件,源码JTImageLabel,JTImageLabel能够附加图片的标签Label控件,图片可以随意更换.位置也能够很好的控制.效果图: <ignore_j ...
- 正则去掉html标签之间的空格、换行符、tab符,但是保留html标签内部的属性空格
今天遇到一个比较少见的去空格: 正则去掉html标签之间的空格.换行符.tab符,但是保留html标签内部的属性空格 JS 举例: "<a href='baidu.com' name= ...
- 正则获取html标签字符串中图片地址
html标签字符串: var htmlStr = "<div class='testClass'><img=http://www.chinanews.com/part/ho ...
- php正则过滤html标签、空格、换行符的代码,提取图片
$descclear = str_replace("r","",$descclear);//过滤换行 $descclear = str_replace(&quo ...
- php用正则匹配出图片img标签中的src路径(兼容)
用php抓图片是个常用的需求,下面提供一个比较兼容的正则表达式来实现php抓取出页面.字符串中所有图片的src. 下面是一个范例,能匹配各种标签格式写法的图片,不管src在什么地方,还是单引号.双引号 ...
- Python:使用正则去除HTML标签(转)
利用正则式处理,不知道会不会有性能问题,没有经过太多测试. 目前我有很多还是使用BeautifulSoup进行这种处理. HTML实体处理的只是用于处理一些常用的实体. # -*- coding: u ...
随机推荐
- 获取在attr.xml中声明的主题样式
在换肤时,先在attr.xml中定义Resource的属性名,再到stytle中,根据不同的主题,给属性赋值. 在布局文件中可直接以 android:background="?attr/a ...
- 送给和我一样曾经浮躁过的PHP程序猿
送给和我一样曾经浮躁过的PHP程序猿 2012年偶决定开始写博客了,不为别的,就希望可以通过博客记录我的成长历程,同时也希望可以帮助一些刚毕业,刚入行业的兄弟姐们 们.我们是一群充满浮躁.抱怨.迷 ...
- HTML: css 修飾文本和字體
因爲這個我認爲不用記,所以關於css 修飾文本&字體的屬性只需要打開css手冊,找到(屬性 > 文本) & (屬性 > 字體)翻看即可. 關於字體屬性: Propertie ...
- js获取各种宽高方法
屏幕的有效宽高: window.screen.availHeightwindow.screen.availWidth 网页可见区域宽:document.body.clientWidth 网页可见区域高 ...
- MySQL出现大量unauthenticated user的问题
发现这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过 慢(不管是不是isp提供的dns服务器的问题或者其他原因), ...
- linux下php-fpm 启动参数及重要配置
约定几个目录 /usr/local/php/sbin/php-fpm/usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php.iniI. php-fp ...
- mysqli_query($link,'SET group_concat_max_len=8192');
mysqli_query($link,'SET group_concat_max_len=8192'); $sql = 'SELECT GROUP_CONCAT(w) FROM ---'; mysql ...
- Euler's totient function
https://en.wikipedia.org/wiki/Euler's_totient_function counts the positive integers up to a given in ...
- pdo封装类
<?php //http://www.imavex.com/php-pdo-wrapper-class/ class db extends PDO { private $error; priva ...
- Delphi 缩放图像代码 - 支持PNG透明通道
要求Delphi2007或者更高版本, 系统要求至少XP-SP2以上 实际上是利用了Windows的windowscodecs.dll这个文件的功能 在VCL里已经封装为TWICImage类 proc ...