zoukankan      html  css  js  c++  java
  • 正则表达试

    if ([html isKindOfClass:[NSStringclass]])

        {

            html = [html stringByReplacingOccurrencesOfRegex:@"@\b(\w+)\b"

                                                  withString:@"<a href="at:$1" style="color:#3485CE">@$1</a>"];

            // #话题#还有bug:文字中间不能有空格

            html = [html stringByReplacingOccurrencesOfRegex:@"#\b(\w*)#"

                                                  withString:@"<a href="topic:$1" style="color:#3485CE">#$1#</a>"];

            // 链接

            NSString *urlRegex = @"(https?)://([a-zA-Z0-9\-.]+)((?:/[a-zA-Z0-9\-._?,:'+\&%$=~*!():@\\]*)+)?";

            html = [html stringByReplacingOccurrencesOfRegex:urlRegex

                                                  withString:@"<a href="$1://$2$3" style="color:#3485CE">$1://$2$3</a>"];

        }

  • 相关阅读:
    循环语句 for , forin , forEach
    Haxe
    Haxe数据类型
    jango中间件的使用
    python的遍历模式
    python文件读写
    python3.5以上自带的虚拟环境在各种环境下的使用方法
    冒泡排序
    工厂方法模式
    redis 配置
  • 原文地址:https://www.cnblogs.com/liyufeng2013/p/3494680.html
Copyright © 2011-2022 走看看