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 ...
随机推荐
- spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable
1.spring mvc返回json数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable 2. @RequestMapping(val ...
- Yii源码阅读笔记(十一)
controller类的render部分,用于渲染视图和布局文件: /** * Returns all ancestor modules of this controller. * 获取当前控制器所有 ...
- anti-pattern - Hard coding
https://en.wikipedia.org/wiki/Hard_coding Considered an anti-pattern, hard coding requires the progr ...
- 【转】Unity3D研究院之通过C#使用Advanced CSharp Messenger(五十)
http://www.xuanyusong.com/archives/2165 Advanced CSharp Messenger 属于C#事件的一种. 维基百科中由详细的说明http://wiki. ...
- 取url的键值对,location的search:从?开始的字符串
function urlArgs(){ var args=""; var query=location.search.substring(1);//去除问号 var pairs=q ...
- sqlserver 获取当前操作的数据库名称
Select Name From Master..SysDataBases Where DbId=(Select Dbid From Master..SysProcesses Where Spid = ...
- Photoshop:通过图片理解通道原理
电脑上的图像通过色光三原色RGB表现,不同颜色存储在不同的通道,所以RGB模式下有3条通道,CMYK模式有4条通道等等 打开一张照片,查看通道 可以看出,显示越白的地方,对应的原色越深. 默认phot ...
- QFile文件操作-QT
#include <QCoreApplication> #include<QFile> #include<QString> #include<QDebug&g ...
- 系统默认Select框 知多少
<div class="user_base_info_list"><div class="user_base_info_lab">学制: ...
- 2014-4-25 运行号:837344 ASCII码排序
#include <iostream> #include <cstdio> #include <cstdlib> #include <string> # ...