gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:45:24 25 4
gpt4 key购买 nike

我有以下网址:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com