views:

23

answers:

1

I'd like to change the case (ie, lowercase to uppercase) of found matches using RegexKitLite but don't know how or if it's possible. In PCRE regex, you can have in the replacement pattern something like \u$1 to uppercase the found match of group 1. I can't see how to do that. Can someone please let me know how?

Thanks in advance

A: 

Use RegexKitLite 4.0s Blocks methods:

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);

Output when run:

2010-08-22 14:25:20.047 RegexKitLite[33454:a0f] Replaced: 'An Example Of Lowercase To Uppercase.'
johne
Thank you, Johne. I'm targetting 10.4, so blocks are out. Sorry, perhaps I should have mentioned that. I'm going to try to do what I want using an NSTask running a perl script. There are other troubles that way, of course, but I feel more able to address them.Ron
Ron Fleckner