Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将NSRegularExpression写入xx:xx:xx?_Iphone_Ios_Xcode - Fatal编程技术网

Iphone 如何将NSRegularExpression写入xx:xx:xx?

Iphone 如何将NSRegularExpression写入xx:xx:xx?,iphone,ios,xcode,Iphone,Ios,Xcode,我试图检查NSString是否为特定格式dd:dd:dd。我正在考虑NSRegularExpression。差不多 /^(\d)\d:\d\d:\d\d)$/?我建议使用 有了这个,并假设在dd:dd:dd'd'中实际上代表0-9之间的一个数字,考虑到Grijesh的附加注释,实现您所需要的应该是相当容易的 以下是从RegexKitLite页面复制的示例: // finds phone number in format nnn-nnn-nnnn NSString *regEx = @"{3}-[

我试图检查
NSString
是否为特定格式dd:dd:dd。我正在考虑
NSRegularExpression
。差不多

/^(\d)\d:\d\d:\d\d)$/?

我建议使用

有了这个,并假设在dd:dd:dd'd'中实际上代表0-9之间的一个数字,考虑到Grijesh的附加注释,实现您所需要的应该是相当容易的

以下是从RegexKitLite页面复制的示例:

// finds phone number in format nnn-nnn-nnnn
NSString *regEx = @"{3}-[0-9]{3}-[0-9]{4}";
NSString *match = [textView.text stringByMatching:regEx];
if ([match isEqual:@""] == NO) {
    NSLog(@"Phone number is %@", match);
} else {
    NSLog(@"Not found.");
}

你有没有试过这样的方法:

NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^\d{2}:\d{2}:\d{2}$"
                                                                       options:0
                                                                         error:&error];

NSUInteger numberOfMatches = [regex numberOfMatchesInString:string
                                                    options:0
                                                      range:NSMakeRange(0, [string length])];
(我还没有测试它,因为我现在不能,但它应该可以工作了)

更新:

NSString *idRegex = @"[0-9][0-9]:[0-9][0-9]:[0-9][0-9]";
NSPredicate *idTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", idRegex];               
for (NSString * str in newArrAfterPars) {
if ([idTest evaluateWithObject:str]) {
}
}

[0-9][0-9][:][0-9][0-9][:][0-9][0-9]