我试图找到如何从“/games/usa/2013-05-01/game1.html”中提取“2013-05-01/game1”,但我不怎么做那。我已经尝试了一些正则表达式,但它没有工作。而且我也不知道这是否是最好的方法。这是我到目前为止所尝试的。如何从字符串中提取字符串?
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"/[0-9]{4}-[0-9]{2}-[0-9]-{2}\//\.*$)" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *newSearchString = [regex firstMatchInString:opening_time options:0 range:NSMakeRange(0, [opening_time length])];
NSString *substr = [opening_time substringWithRange:newSearchString.range];
NSLog(@"%@", substr);
任何帮助,将不胜感激。
你能依赖围绕字符串的格式吗?它会永远像你的榜样吗? –
是的,总是那样的! –