I am trying to distinguish 2 files (in NSString format). As far as I know, this can be done by comparing and matching the regex. The format of the two jpg files that I have is:
butter.jpg
oil-1.jpg
My question is: what regular expression can I write to fit the two lines above? I searched and found an example of an expression, but I'm not sure how it reads and thinks it is wrong.
Here is my code:
NSString *exampleFileName = [NSString stringWithFormat:@"butter-1.jpg"]; NSString *regEx = @".*l{2,}.*"; NSPredicate *regExTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx]; if ([regExTest evaluateWithObject:exampleFileName] == YES) { NSLog(@"Match!"); } else { NSLog(@"No match!"); }
EDIT:
I tried using the following:
NSString *regEx = @"[az]+-[0-9]+.+jpg";
to try to match:
NSString *exampleFileName = [NSString stringWithFormat:@"abcdefg-112323.jpg"];
Tested with
abc-11.jpg (Match)
abcsdas-.jpg (No match)
abcdefg11. (No match)
abcdefg-3123.jpg (Match)
At the moment it works, but I want to exclude any chances that it might not be, any inputs?
source share