1
我使用preg_split
拆分基於PHP中的正則表達式的字符串,用下面的代碼:可可使preg_split相當於
$array = preg_split("~(?<!\*),~", $string);
什麼是Cocoa等效?
任何幫助表示讚賞。
我使用preg_split
拆分基於PHP中的正則表達式的字符串,用下面的代碼:可可使preg_split相當於
$array = preg_split("~(?<!\*),~", $string);
什麼是Cocoa等效?
任何幫助表示讚賞。
最後寫使用NSRegularExpression
+ (NSArray *)preg_split:(NSString *)expression withSubject:(NSString *)subject {
NSRegularExpression *exp = [NSRegularExpression regularExpressionWithPattern:expression options:0 error:nil];
NSArray *matches = [exp matchesInString:subject options:0 range:NSMakeRange(0, [subject length])];
NSMutableArray *results = [[NSMutableArray alloc] init];
for (NSTextCheckingResult *match in matches) {
[results addObject:[subject substringWithRange:[match range]]];
}
return results;
}
http://stackoverflow.com/a/2062338/127880 – 2013-02-11 07:07:19
看起來你必須檢查出可可的各種第三方的正則表達式庫我自己的方法 – Jay 2013-02-11 07:40:56