我有以下网址:
和以下正则表达式:
NSRegularExpression * regexTags = [NSRegularExpression regularExpressionWithPattern:@"tags/\\[a-zA-Z0-9]+/media/recent" options:NSRegularExpressionCaseInsensitive error:&error];
NSArray* tagMatch = [regexTags matchesInString:self.currentRequestURL_
options:0 range:NSMakeRange(0, [self.currentRequestURL_ length])];
为什么这与正则表达式不匹配?
最佳答案
你的正则表达式本身有错误
正则表达式
@"tags/\\[a-zA-Z0-9]+/media/recent"
匹配 tags/\picoftheday/media/recent
但你需要 tags/[a-zA-Z0-9]+/media/recent
匹配 tags/picoftheday/media/recent
有一个有用的在线测试器可以测试你的正则表达式是否匹配字符串 http://regexpal.com/
关于iphone - 匹配一个或多个字母数字的 NSRegularExpression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333619/