Objective c 在NSString中查找非常量char.set
我有一个NSString,其中包含以下数据: {SCENE*169/doprava/doprava_tabulka{}{{}{{}1299234095}{SCENE*169/doprava/doprava_video{}{}{}1299234166} 我想删除“括号和数字”部分,但数字不是常量 {}{}{}{}1299234095 {}{}{}{}1299234166Objective c 在NSString中查找非常量char.set,objective-c,cocoa,cocoa-touch,Objective C,Cocoa,Cocoa Touch,我有一个NSString,其中包含以下数据: {SCENE*169/doprava/doprava_tabulka{}{{}{{}1299234095}{SCENE*169/doprava/doprava_video{}{}{}1299234166} 我想删除“括号和数字”部分,但数字不是常量 {}{}{}{}1299234095 {}{}{}{}1299234166 如何删除此项 我会使用NSRegularExpression NSRegularExpression *regex = [NSR
如何删除此项 我会使用
NSRegularExpression
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
@"((?: \\{\\}){3} [0-9]+)" options:0 error:nil];
NSMutableString *str = [NSMutableString stringWithString:
@"{SCENE*169/doprava/doprava_tabulka {} {} {} 1299234095} {SCENE*169/doprava/doprava_video {} {} {} 1299234166}"];
[regex replaceMatchesInString:str options:0 range:NSMakeRange(0, [str length]) withTemplate:@""];
str
这里的值是{SCENE*169/doprava/doprava_tabulka}{SCENE*169/doprava/doprava_video}
但是如果您为iOS开发,它只能从3.2开始使用。我可以从您的代码中使用类似于:@“((?:\\{\}){3}[0-9]+)”的方法:“StringByReplacingOfString:withString:”这样会更容易。但是我无法编写此条件的良好格式否,
stringByReplacingOccurrencesOfString:withString:
仅替换常量子字符串。