/ Published in: Objective C
                    
                                        
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
 Subscribe to comments
                    Subscribe to comments
                
                