Re: Running a regular expression on an NSString
Re: Running a regular expression on an NSString
- Subject: Re: Running a regular expression on an NSString
- From: Matt Neuburg <email@hidden>
- Date: Fri, 4 Jan 2002 08:36:05 -0800
On Fri, 28 Dec 2001 14:00:29 -0800, Steven Frank <email@hidden> said:
>
Is there an easy way to run a regular expression on an NSString? I
>
don't think NSScanner is going to cut it in this particular case.
I asked the same question on just about my first day using Cocoa. :-) I
find the lack of built-in regex support astounding. How hard would it be,
especially since we know Perl is sitting right there on the same machine?
In the end, in fact, I included a Perl script in my project and called it
with NSTask. I got some help from various folks here on how to structure
the necessary incantation, so I pass it along:
// run perl script
NSTask* wdct = [[NSTask alloc] init];
NSPipe* pipe = [NSPipe pipe];
NSString* reply;
NSFileHandle* handle = [pipe fileHandleForReading];
[wdct setStandardOutput: pipe];
[wdct setLaunchPath: [[NSBundle mainBundle]
pathForResource: @"wdct" ofType:nil]];
[wdct setArguments: [NSArray arrayWithObject: whatever]];
[wdct launch];
reply = [[NSString alloc] initWithData: [handle readDataToEndOfFile]
encoding: NSASCIIStringEncoding];
HTH - m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes gar anthropoi tou eidenai oregontai phusei