可以編寫的正則表達式與幾個串
也可以在 http://regexpal.com 其不同測試的正則表達式,因爲你刪除\在表達式例如 (\ d {2})([./ (\ d {2,4})
NSError *error = NULL;
NSString *expForSlash = @"(\\d{2})((\/)|(\.))(\\d{2})((\/)|(\.))(\\d{4}|\\d{2})";
NSString *expMonthStrNew = @"(Jan|Feb|Mar(ch)?|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\\s?)(\\d{2}|\\d{1})(\,?)(\\s?)(\\d{4}|\\d{2})";
NSString *expForreg = [NSString stringWithFormat:@"%@|%@", expForSlash, expMonthStrNew];//@"(May|Jun)(\\s?)(\\d{2})(\,?)(\\s?)(\\d{4})";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:expForreg
options:NSRegularExpressionCaseInsensitive
error:&error];
NSArray *matches = [regex matchesInString:tesText options:0 range:NSMakeRange(0, [tesText length])];
來源
2015-05-07 07:38:58
miv
可能重複:[正則表達式各種日期格式(http://stackoverflow.com/q/11516129/1578604)。 – Jerry