【发布时间】:2015-09-30 05:26:41
【问题描述】:
我的 NSString 模式效果不佳。
NSString *pattern = @"/api/v1/news/([0-9]+)/\\?categoryId=([0-9]+)";
NSString *string = urlString;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:nil];
为什么它也匹配下面的字符串?
/api/v1/news/123/?categoryId=22abc
我只想匹配
/api/v1/news/123/?categoryId=22
其中 123 和 22 可以是可变数字。
【问题讨论】:
-
显示其余代码,您可以在其中访问
NSTextCheckingResult。 -
在末尾加上 \b 或 $ 以确保路径以一位或多位数字结尾。
-
ICU 用户指南:Regular Expressions
标签: objective-c regex nsregularexpression