• 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: simple regex with NSTask
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple regex with NSTask


  • Subject: Re: simple regex with NSTask
  • From: Nathan Day <email@hidden>
  • Date: Fri, 16 Feb 2007 17:06:30 +1100

Instead of using NSTask and sed, have thought of using a Objective-C Regex library like 'AGRegex', you can get 'AGRegex' with darwin ports if you have that installed

On 13/02/2007, at 2:06 AM, Al Skipp wrote:

I'm attempting to get a simple regex working by using NSTask with a shell script, though without much joy. The regex removes characters I don't want included in file names - the problem is that all paragraphs are extracted and the returned string is only one line of text.
The details of the problem are outlined below, any suggestions most appreciated.


It works fine when called through Applescript:

***********************************
Applescript:
set testString to "just::;;
testing,,...
///??now"

set resultString to text of (do shell script "echo " & quoted form of testString & "| sed -e 's/[/,;:.\\?]//g'")

resultString is:
"just
testing
now"
***********************************

However when I attempt to do the same with a shell script called with NSTask, the paragraphs are removed:

Shell script:
#! /bin/sh
echo $1 | sed -e 's/[/,;:.\?]//g'

result is:
"just testing now"

***********************************
An extract of the objective-C code is below

NSString *testString = @"just???\ntesting...\n:::::now"];

NSArray *arg = [NSArray arrayWithObject:testString];

NSTask *task = [[[NSTask alloc]init]autorelease];
[task setLaunchPath:scriptPath];
[task setArguments:arg];

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file = [pipe fileHandleForReading];

[task launch];

NSData *data = [file readDataToEndOfFile];
NSString *newString = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]autorelease];
NSLog(@"verified string, %@", newString);
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: simple regex with NSTask
      • From: Jerry Krinock <email@hidden>
References: 
 >simple regex with NSTask (From: Al Skipp <email@hidden>)

  • Prev by Date: Re: NSWindowController versus other NIB Owners
  • Next by Date: Re: Frustration trying to get NSConnection/NSPort working (feels like it should be simpler ...)
  • Previous by thread: simple regex with NSTask
  • Next by thread: Re: simple regex with NSTask
  • Index(es):
    • Date
    • Thread