zoukankan      html  css  js  c++  java
  • 使用正则提取url(iOS)

    直接上代码:

     

      NSString *string = @"我是大大 www.baidu.com 咪咪咪";    

        NSError *error;

        NSString *regulaStr = @"\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>???“”‘’]))";

        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr                                                                          options:NSRegularExpressionCaseInsensitive error:&error];

        NSLog(@"error:%@", error);

        NSArray *arrayOfAllMatches = [regex matchesInString:string options:NSMatchingReportCompletion range:NSMakeRange(0, [string length])];

        for (NSTextCheckingResult *match in arrayOfAllMatches)

        {

            NSString* substringForMatch = [string substringWithRange:match.range];

            NSLog(@"substringForMatch");

            NSLog(@"%@", substringForMatch);

        }

  • 相关阅读:
    多表关联 update
    pdf转成图片
    JS中也可以使用JSTL和EL标签
    JSTL String时间转成 date
    SQL函数创建错误
    使用 itext、flying-saucer 实现html转PDF(转)
    Redis 命令参考
    1、课程介绍
    layui 弹出框提交表单
    一张图解析
  • 原文地址:https://www.cnblogs.com/bug-sniper/p/4773577.html
Copyright © 2011-2022 走看看