iPhone / Cocoa:NSPredicate regex replace? [英] iPhone/Cocoa: NSPredicate regex replace?
本文介绍了iPhone / Cocoa:NSPredicate regex replace?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据本指南,我可以使用NSPredicate在字符串上进行正则表达式匹配,即perl等价于 $ my_string =〜m / [some regex] /
According to this guide, I can use NSPredicate to do regex matching on strings, i.e., the perl equivalent of $my_string =~ m/[some regex]/
但是我可以做regex替换,即等价于这个perl表达式: $ my_string =〜s / [pattern] / [replacement] / g
?
But can I do regex replace, i.e. the equivalent of this perl expression: $my_string =~ s/[pattern]/[replacement]/g
?
推荐答案
Google Toolbox for Mac 有一些有用的正则表达式功能。它在iPhone上工作。请查看 GTMRegex。 h 。 NSString上有一个类别:
Google Toolbox for Mac has some useful regex functionality. It works on the iPhone. Take a look at GTMRegex.h. There is a category on NSString with this method:
- (NSString *)gtm_stringByReplacingMatchesOfPattern:(NSString *)pattern withReplacement:(NSString *)replacementPattern;
这篇关于iPhone / Cocoa:NSPredicate regex replace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文