Hi to all overflowers,
I'm scratching my head around putting a regular expression
inside an NSPredicate
.
I would like to move all our thumbnails from Documents directory into Caches directory and catch em'all I've created this regex: _thumb(@[2-3]x)?\.jpg
.
Here on regex101.com you can see the above regex working with this test data:
grwior_thumb.jpg <- match
grwior.jpg
vuoetrjrt_thumb@2x.jpg <- match
vuoetrjrt.jpg
hafiruwhf_thumb.jpg <- match
hafiruwhf_thumb@2x.jpg <- match
hafiruwhf_thumb@3x.jpg <- match
hafiruwhf.jpg
But when I put it in the code it's not matching anything:
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
// Find and move thumbs to the caches folder
NSArray<NSString *> *mediaFilesArray = [fileManager contentsOfDirectoryAtPath:documentsPath error:&error];
NSString *regex = @"_thumb(@[2-3]x)?\\.jpg";
NSPredicate *thumbPredicate = [NSPredicate predicateWithFormat: @"SELF ENDSWITH %@", regex];
NSArray<NSString *> *thumbFileArray = [mediaFilesArray filteredArrayUsingPredicate:thumbPredicate];
thumbFileArray
has always 0 elements...
What am I doing wrong?