Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:20+00:00 2026-05-29T08:05:20+00:00

Now my app targets >iOS4 I am trying to remove dependencies on non Apple

  • 0

Now my app targets >iOS4 I am trying to remove dependencies on non Apple frameworks where possible.

I have this code currently

    NSString *destination =@"HHH-DDDD>dddd,ffff";
    NSString *searchString = destination;
    NSString *regexString  = @"[^a-zA-Z\?]";
    NSArray  *splitArray   = NULL;
    splitArray = [searchString componentsSeparatedByRegex:regexString];

This produces an array with string elements between all of the characters. i.e. “HHH”,”DDDD”,”dddd”,”ffff”.

There doesn’t seem to be an equivalent in the NSRegularExpression at all or am I reading the documentation wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:05:22+00:00Added an answer on May 29, 2026 at 8:05 am

    seems you’re right but you could use a category:

    #import "NSString+RegEx_Array.h"
    
    @implementation NSString (RegEx_Array)
    
    - (NSArray*)componentsSeparatedByRegex2:(NSString *)pattern
    {
        NSUInteger pos = 0;
        NSRange area = NSMakeRange(0, [self length]);
    
        NSRegularExpression *regEx = [NSRegularExpression 
                                      regularExpressionWithPattern:pattern 
                                      options:0 error:nil];
    
        NSArray *matchResults = [regEx matchesInString:self options:0 range:area];
    
        NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:matchResults.count];
    
        for (NSTextCheckingResult *result in matchResults) {
            NSRange substrRange = NSMakeRange(pos, [result range].location-pos);
            [returnArray addObject:[self substringWithRange:substrRange]];
            pos = [result range].location + [result range].length;
        }
    
        if (pos < area.length) {
            [returnArray addObject:[self substringFromIndex:pos]];
        }
    
        return returnArray;
    }
    
    @end
    

    but I have to admit, it isn’t that performant like RegexKitLite. Heres the output for a nonsense file:

    2012-02-08 00:16:32.251 shittyagain[96057:c03] String-Length: 36355200
    2012-02-08 00:16:36.420 shittyagain[96057:c03] Time taken RegexKitLite: 4.167
    2012-02-08 00:16:42.989 shittyagain[96057:c03] Time taken NSRegularExp: 6.568
    

    and the testing code:

    NSString *regx = @"[^a-zA-Z\?]";
    NSString *file = [[NSBundle mainBundle]pathForResource:@"reallylong" ofType:nil];
    NSString *searchString = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
    
    NSLog(@"String-Length: %ld", searchString.length);
    
    NSDate *preDate = [NSDate date];
    [searchString componentsSeparatedByRegex:regx];
    NSLog(@"Time taken RegexKitLite: %1.3f", [preDate timeIntervalSinceNow]*-1);
    
    NSDate *preDate2 = [NSDate date];
    [searchString componentsSeparatedByRegex2:regx];
    NSLog(@"Time taken NSRegularExp: %1.3f", [preDate2 timeIntervalSinceNow]*-1);
    

    I’m not sure if the difference really matters because the file has a size of ~36mb but just in case someone needs it really fast he has to use the RegexKitLite. I would like if someone could post some real performance test and/or for for default NSRegularExpression methods. I want to know which one is faster =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have iOS4 specific code (ie the MKMapView overlays) in an
I create my first iphone app now i want submit this on appstore so
Currently, I have an iPhone app published in AppStore. I've developed it using XCode
I'm developing an offline web app that (for now) only targets Safari on the
I have an application with two targets (for two versions of the app, free
How is this possible? I configured my iPhone app like this: I pushed it
I'm scratching my head over this. I have a moderately successful app which has
I have designed attached screens for my app. The app targets android 1.6 and
Trying to send an app to Apple's App Store. Xcode 4.3.2. Successfully sent the
Almost every ios app now has something like Feed option. Programming that usually includes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.