I'm a total noob to regexes. I'm trying to come up with a regex that will capture text in braces. Example:
{t} this text shouldn't {1}{2} be captured {3} -> t, 1, 2, 3
This is what I've tried:
NSString *text = @"{t} this text shouldn't {1}{2} be captured {3}";
NSString *pattern = @"\\{.*\\}"; // The part I need help with
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern
options:kNilOptions
error:nil];
NSArray *matches = [regex matchesInString:text
options:kNilOptions
range:NSMakeRange(0, text.length)];
for (NSTextCheckingResult *result in matches)
{
NSString *match = [text substringWithRange:result.range];
NSLog(@"%@%@", match , (result == matches.lastObject) ? @"" : @", ");
}
It yielded {t} this text shouldn't {1}{2} be captured {3}
.
I'm sorry for such a straightforward request, but I'm just in a hurry and I don't know much about regexes.