-(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 /> 标签的更多相关文章

  1. C#正则过滤HTML标签并保留指定标签的方法

    本文实例讲述了C#正则过滤html标签并保留指定标签的方法.分享给大家供大家参考,具体如下: 这边主要看到一个过滤的功能: public static string FilterHtmlTag(str ...

  2. Python3正则去掉HTML标签

    Python3正则去掉HTML标签 1.引用一段代码 import re html = '<pre class="line mt-10 q-content" accuse=& ...

  3. Python图形编程探索系列-04-网上图片与标签组件的结合

    跳转到自己的博客 任务设定 任务:从网上找到一张图片,然后将其显示在标签上? 网上图片网站:http://pic.58pic.com/58pic/17/56/38/52w58PICtER_1024.j ...

  4. 能够附加图片的标签控件iOS项目源码

    这个源码案例是能够附加图片的标签控件,源码JTImageLabel,JTImageLabel能够附加图片的标签Label控件,图片可以随意更换.位置也能够很好的控制.效果图: <ignore_j ...

  5. 正则去掉html标签之间的空格、换行符、tab符,但是保留html标签内部的属性空格

    今天遇到一个比较少见的去空格: 正则去掉html标签之间的空格.换行符.tab符,但是保留html标签内部的属性空格 JS 举例: "<a href='baidu.com' name= ...

  6. 正则获取html标签字符串中图片地址

    html标签字符串: var htmlStr = "<div class='testClass'><img=http://www.chinanews.com/part/ho ...

  7. php正则过滤html标签、空格、换行符的代码,提取图片

    $descclear = str_replace("r","",$descclear);//过滤换行 $descclear = str_replace(&quo ...

  8. php用正则匹配出图片img标签中的src路径(兼容)

    用php抓图片是个常用的需求,下面提供一个比较兼容的正则表达式来实现php抓取出页面.字符串中所有图片的src. 下面是一个范例,能匹配各种标签格式写法的图片,不管src在什么地方,还是单引号.双引号 ...

  9. Python:使用正则去除HTML标签(转)

    利用正则式处理,不知道会不会有性能问题,没有经过太多测试. 目前我有很多还是使用BeautifulSoup进行这种处理. HTML实体处理的只是用于处理一些常用的实体. # -*- coding: u ...

随机推荐

  1. Introduction to Structured Data

    https://developers.google.com/search/docs/guides/intro-structured-data Structured data refers to kin ...

  2. Gradient

    https://en.wikipedia.org/wiki/Gradient

  3. php thread

    1-include('w_fun.php');页面已经在执行,则修改include中的函数,倒置旧页面不受影响:新页面生效:2-time  轮流 echo ' <script> windo ...

  4. Apache Apex

    http://apex.apache.org/docs.html https://apex.apache.org/docs/apex/application_development/

  5. ThreadLocal知识总结

    以前学习<Thinking in Java>时,了解过ThreadLocal,但没做笔记.现在又忘记了.嗯,要勤动笔.API中ThreadLocal的方法: public T get() ...

  6. Koala编译less

    下载地址:http://koala-app.com/index-zh.html 用Koala可以用来编译less,软件也是简单明了,平时开着其他软件编辑less,只要打开Koala,勾选“自动编译”后 ...

  7. android 5.0 (lollipop)源码编译环境搭建(Mac OS X)

    硬件环境:MacBook Pro Retina, 13-inch, Late 2013 处理器  2.4 GHz Intel Core i5 内存  8 GB 1600 MHz DDR3 硬盘60G以 ...

  8. [LeetCode] Maximal Rectangle(good)

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  9. An Implementation of Double-Array Trie

    Contents What is Trie? What Does It Take to Implement a Trie? Tripple-Array Trie Double-Array Trie S ...

  10. angularJs:动态效果之:显示与隐藏(该例对比了普通赋值,层次赋值,事件的写法对比)

    testShowAndHiddern.html <!DOCTYPE html> <html ng-app="MyModule"> <head> ...