For the regex: @"^\\s*(.+?)(?:\\s+\\#?(\\d+(?:\\.\\d+)?)(?:\\s*(?:\\(?\\s*of|-)\\s*(\\d+)\\s*\\)?)?)?\\s*(?:(\\(.*)\\s*)?$"
and the input: @"xxx xxxxx - xxxxxxx xx xxx xxxx 01 (xxx) (1111) (xxxxxxxxx - xxxxxx)"
Called like so:
NSDictionary *matches = [input dictionaryByMatchingRegex:regex
options:RKLComments
range:NSMakeRange(0, [fileName length])
error:NULL
withKeysAndCaptures:
@"a", 1,
@"b", 2,
@"c", 3,
@"d", 4,
nil];
I get @"(xxx) (1111) (xxxxxxxxx - xxxxxx)" returned for key @"c", even though it should be the 4th capture group. Other regex parsers function this way, and it makes the dictionaryByMatchingRegex functions much less useful if the capture groups don't retain absolute numbering.
I'm using RegexKitLite by including the .h and .m files in my project source. I'm in Xcode 4 writing a Mac app targeting the latest versions of the framework (10.6).