/ Published in: Objective C
![](/img/icon_sav.png?v3)
Extract groups from a Regular Expression
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
NSRegularExpression* exp = [NSRegularExpression regularExpressionWithPattern:@"(put)-(expression)-(here)" options:NSRegularExpressionSearch error:&error]; if (error) { NSLog(@"%@", error); } else { NSTextCheckingResult* result = [exp firstMatchInString:testString options:0 range:NSMakeRange(0, [productDescription length] ) ]; if (result) { NSRange groupOne = [result rangeAtIndex:1]; // 0 is the WHOLE string. NSRange groupTwo = [result rangeAtIndex:2]; NSRange groupThree = [result rangeAtIndex:3]; NSLog( [testString substringWithRange:groupOne] ); NSLog( [testString substringWithRange:groupTwo] ); NSLog( [testString substringWithRange:groupThree] ); } }
Comments
![RSS Feed for Comments RSS Icon](/images/rss.png?v3)