• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Running a regular expression on an NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Running a regular expression on an NSString
      • From: "Jeff Galyan" <email@hidden>
    • Re: Running a regular expression on an NSString
      • From: "Erik M. Buck" <email@hidden>
  • Prev by Date: Re: OOP Clarification
  • Next by Date: Re: OOP Clarification
  • Previous by thread: Re: Can these be done in Cocoa?
  • Next by thread: Re: Running a regular expression on an NSString
  • Index(es):
    • Date
    • Thread