I’m making a regular expression for the following line:
Table 'Joella VIII' 6-max Seat #4 is the button
So far, I’ve got this:
self.tableDetailsRegex = [NSRegularExpression regularExpressionWithPattern:@"Table '[A-Za-z0-9 ]*' [0-9]+-max Seat #[0-9]+ is the button" options:NSRegularExpressionAllowCommentsAndWhitespace error:nil];
if([self.tableDetailsRegex numberOfMatchesInString:line options:NSMatchingReportCompletion range:NSMakeRange(0, line.length)] == 1)
{
NSLog(@"%@", line);
}
So, my regular expression is:
Table '[A-Za-z0-9 ]*' [0-9]+-max Seat #[0-9]+ is the button
And I’m sure the selected line comes by at some point, because I’m printing all the lines a bit further in my code…
Your problem is in the options you are using. From the NSRegularExpression Class Reference,
NSRegularExpressionAllowCommentsAndWhitespacemeans that whitespace and anything after a#in the regular expression will be ignored. With that option enabled, the regular expression acts like this:You probably want to pass 0 for the options, so that none of them get enabled.