NSPredicate issue for getting an image url with its size in URL

Here's my problem.

I'm using an HTML parser for parsing an HTML content.

When i'm matching an image usig this pattern

http://www.site.com/path/to/image/image-name-heightxwidth.extension

I'm want get on my core data database the matching url for this image using this pattern :

http://www.site.com/path/to/image/image-name.extension

What is the correct "predicate with format" i should use for preforming my request ?

EDIT : Here's the code for where i perform my request on the data base

- (WPImage *)imageMatchingUrl:(NSString *)urlString {

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"url CONTAINS %@",urlString];
    ALog(@"WPImage for urlString %@ found ? : %@",urlString, [self getEntities:NSStringFromClass([WPImage class]) withPredicate:predicate][0]?@"Yes":@"No");
    return [self getEntities:NSStringFromClass([WPImage class]) withPredicate:predicate][0];

}

Answers


Try regular expression NSPattern cannot do this, this should do the job:

    NSString *st1 = @"http://www.site.com/path/to/image/image-name-300x200.extension";

    NSRange   searchedRange = NSMakeRange(0, [st1 length]);
    NSString *pattern = @"-\\d+x\\d+";
    NSError  *error = nil;

    NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    NSArray* matches = [regex matchesInString:st1 options:0 range: searchedRange];
    for (NSTextCheckingResult* match in matches)
    {
        NSString* matchText = [st1 stringByReplacingCharactersInRange:[match range] withString:@""];

        NSLog(@"Match: %@", matchText);
    }

Need Your Help

How do you flip an equation (exchange LHS with RHS) in Maple?

swap equation maple

I have an equation which has been reduced to the form