NSString regex string matching/search

ios, nsstring, objective-c, regex

Solution

Problem Solved !!

This code give exactly what you want,

NSString *yourString = @"random ++qwerty/asdf random ++derty/asdf random ++noty/asdf";
NSError *error = NULL;

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"random \\+\\+(\\w+)/asdf" options:NSRegularExpressionCaseInsensitive error:&error];


[regex enumerateMatchesInString:yourString options:0 range:NSMakeRange(0, [yourString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){

    // detect
    NSString *insideString = [yourString substringWithRange:[match rangeAtIndex:1]];

    //print
    NSLog(@"%@",insideString);

}];

Output: qwerty derty noty

Problem

I have a string like @"random ++qwerty/asdf" and I want to fish out the qwerty part. The "random ++" and "/asdf" will always be the same. How would I go about doing this using regular expressions? I'm confused as to how they work.

Original source