iphone - 匹配一个或多个字母数字的 NSRegularExpression

标签 iphone objective-c ios ipad nsregularexpression

我有以下网址:

https://api.instagram.com/v1/tags/picoftheday/media/recent?access_token=29088696%2Efd3325f%2E7e277194e17340788abc72583dfd48b3

和以下正则表达式:

 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/

相关文章:

iphone - 使用 Telerik TestStudio 和 Jenkins 的连续 iPhone 集成测试服务器

javascript - 图像意外地未在 React Native 教程中渲染

iphone - ASIFormDataRequest "_OBJC_CLASS_$_ASIFormDataRequest"中的错误,引用自 :

ios - iOS 不同设备的导航栏颜色略有不同

iOS:动态标签/验证错误的辅助功能支持?

iphone - UITableView在离开框架时在单元格上随机滴答

ios - 在 iOS 9 中, native Facebook 应用无法通过 Facebook 登录打开

iphone - 当我将新 View Controller 推送到 self.navigation Controller 时应用程序崩溃了

ios - 从 NSArray 更改 UIImageView 中的 UIImage

iphone - 发行时NSString崩溃