需要一个正则表达式来插入 2 个字符串对象,它们之间必须有一个非零的数字

Need a regular expression for inserting 2 string objects between which there must be a number other than zero

我是 Objective-C 的初级程序员。 实际情况如下,当我使用 NSPredicate class 从字典中提取字符串时。 请帮我找到插入 2 个字符串对象的正则表达式,它们之间必须有一个非零的数字。

示例:

prefixPattern = @"2.";
suffixPattern = @".0.0.0";

那么 finalPattern 必须像 @"%@SingleDigitRequiredHereWhichIsNotZero%@",prefixPattern,suffixPattern

搜索结果应该像 2.1.0.0.0 , 2.2.0.0.0 但不能像 2.0.0.0.0

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"header beginswith[c] %@",prefixPattern];
searchedHeader = [_jsonDataArray filteredArrayUsingPredicate:predicate];

//Filter 2
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"header endswith[c] %@",suffixPattern];
searchedHeader2 = [searchedHeader filteredArrayUsingPredicate:predicate2];

//Filter 3
NSPredicate *predicate3 = [NSPredicate predicateWithFormat:@"header matches '[%@][1-9][%@]'",prefixPattern,suffixPattern];
//In the above line I m trying to exclude zero. Here I want only a single digit which is not zero.
searchedHeader3 = [searchedHeader filteredArrayUsingPredicate:predicate3];
NSLog(@"%@",[searchedHeader3 description]);

试试这个,它将模式组合成单独的一行

NSString *prefixPattern = @"2";
NSString *suffixPattern = @"0.0.0";
NSString *pattern = [NSString stringWithFormat:@"%@.[1-9].%@", prefixPattern, suffixPattern];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"header matches %@", pattern];
searchedHeader2 = [searchedHeader filteredArrayUsingPredicate:predicate];