Yet Another Egregious Example of Regex Usage:
Requires RegexKitLite. Uses the regex (?s).
to split a string of unicode characters in to a NSArray
. The .
regex operator matches everything but new-line characters by default, and the sequence (?s)
says Turn on the Dot All regex option
which allows .
to match new-line character as well. Important since we obviously pass over at least \n
in the example below.
#import <Foundation/Foundation.h>
#import "RegexKitLite.h"
// Compile with: gcc -std=gnu99 -o unicodeArray unicodeArray.m RegexKitLite.m -framework Foundation -licucore
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
unichar uc[1024];
for(NSUInteger idx = 0UL; idx < 1024UL; idx++) { uc[idx] = (unichar)idx; }
NSArray *unicharArray = [[NSString stringWithCharacters:uc length:1024UL] componentsMatchedByRegex:@"(?s)."];
NSLog(@"array: %@", [unicharArray subarrayWithRange:NSMakeRange(32UL, (1024UL - 32UL))]);
[pool release];
return(0);
}