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);

        }

  • 相关阅读:
    Android开发之Sqlite的使用
    ZOJ 3607 Lazier Salesgirl
    ZOJ 3769 Diablo III
    ZOJ 2856 Happy Life
    Ural 1119 Metro
    Ural 1146 Maximum Sum
    HDU 1003 Max Sum
    HDU 1160 FatMouse's Speed
    Ural 1073 Square Country
    Ural 1260 Nudnik Photographer
  • 原文地址:https://www.cnblogs.com/bug-sniper/p/4773577.html
Copyright © 2011-2022 走看看