0
我想使用RegexKitLite更改大小寫(即,小寫字母大寫)找到的匹配項,但不知道如何或是否可能。在PCRE正則表達式中,您可以使用替換模式,例如\ u $ 1到大寫組1的匹配項。我看不到如何做到這一點。有人可以讓我知道如何?RegexKitLite替換模式更改發現匹配的情況
在此先感謝
我想使用RegexKitLite更改大小寫(即,小寫字母大寫)找到的匹配項,但不知道如何或是否可能。在PCRE正則表達式中,您可以使用替換模式,例如\ u $ 1到大寫組1的匹配項。我看不到如何做到這一點。有人可以讓我知道如何?RegexKitLite替換模式更改發現匹配的情況
在此先感謝
使用RegexKitLite 4.0s塊方法:
NSString *string = @"An example of lowercase to uppercase.";
NSString *replaced = [string stringByReplacingOccurrencesOfRegex:@"\\w+" usingBlock:^NSString *(NSInteger captureCount, NSString * const capturedStrings[captureCount], const NSRange capturedRanges[captureCount], volatile BOOL * const stop) {
return([capturedStrings[0] capitalizedString]);
}];
NSLog(@"Replaced: '%@'", replaced);
輸出運行時:
2010-08-22 14:25:20.047 RegexKitLite[33454:a0f] Replaced: 'An Example Of Lowercase To Uppercase.'
謝謝你,強尼。我的目標是10.4,所以塊都沒有了。對不起,也許我應該提到這一點。我將嘗試使用運行perl腳本的NSTask來執行我想要的操作。當然還有其他的麻煩,但我覺得更能夠解決它們。 Ron – 2010-08-23 06:55:43