Objective C - RegexKitLite - Parsing inner contents of a string, ie: start(.*?)end

Posted by Stu on Stack Overflow See other posts from Stack Overflow or by Stu
Published on 2010-06-10T17:11:14Z Indexed on 2010/06/10 17:12 UTC
Read the original article Hit count: 324

Please consider the following:

NSString *myText = @"mary had a little lamb";
NSString *regexString = @"mary(.*?)little";

for)NSString *match in [myText captureComponentsMatchedByRegex:regexString]){

NSLog(@"%@",match);

}

This will output to the console two things:

1) "mary had a little" 2) "had a"

What I want is just the 2nd bit of information "had a". Is there is a way of matching a string and returning just the inner part?

I'm fairly new to Objective C, this feels a rather trivial question yet I can't find a less messy way of doing this than incrementing an integer in the for loop and on the second iteration storing the "had a" in an NSString.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about regex