0
我想搜索字符串中的模式。在下面的代码中,模式字符串'*'可以是任何字符。搜索NSString中的模式
我从here得到了这个示例代码,但它不适用于我。
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 string要img_1.png & img.png
我得到这个O/p - > match:img_1.png或者它可以是img = img,其中ai想要img_1.png&im g.png – JiteshW
已更新我的回答 – Andy
谢谢,解决了我的问题。 – JiteshW