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: "Jeff Galyan" <email@hidden>
- Date: Fri, 04 Jan 2002 10:34:23 -0700
Why not use the std C regex functionality on a C string?
The NSString documentation tells you how to get a C string from an NSString.
--Jeff
On 1/4/02 9:36 AM, "Matt Neuburg" <email@hidden> wrote:
>
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.