Я хочу найти шаблон в строке. В приведенном ниже коде строка шаблона '*' может быть любым символом.
Я получил этот пример кода из здесь, но у меня это не работает.
NSString *string;
NSString *pattern;
NSRegularExpression *regex;
string = @"img=img_1.png or it can be img=img.png";
pattern = @"img=*.png";
regex = [NSRegularExpression
regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:nil];
NSArray *matches = [regex matchesInString:string
options:0
range:NSMakeRange(0, [string length])];
NSLog(@"matches - %@", matches);
for (NSTextCheckingResult *match in matches)
{
NSRange range = [match rangeAtIndex:1];
NSLog(@"match: %@", [string substringWithRange:range]);
}
Я хочу, чтобы строка optput была img_1.png и img.png