• 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
perl regex works differently within a "do shell script" than from within perl
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

perl regex works differently within a "do shell script" than from within perl


  • Subject: perl regex works differently within a "do shell script" than from within perl
  • From: John McKenzie <email@hidden>
  • Date: Fri, 27 Apr 2007 15:28:40 -0400

Here's something that's puzzling me.

I need to do some text cleanup on the contents of the clipboard. One thing I need to do is remove leading and trailing spaces, while preserving spaces within the string. 

This regex

s/^\s+//g;

does a great job of removing all __leading__ spaces when used within a perl script.

test case:

$_ = "       /Volume       s/et cetera/     ";
s/^\s+//g; 
print "$_";

gives me a result of 

/Volume       s/et cetera/     

which preserves some trailing spaces which you can't see above. Great, works as expected.

However, when I put it in an Applescript like so:

set fixedName to do shell script "echo " & stringFromTheClipboard & "| perl -pe s/^\\s+//g;" 

fixedName gives me a result of

/Volume s/et cetera/

with trailing spaces also removed, and multiple spaces condensed down to one.

It seems as if within AppleScript, the ^ "start of line" token is being ignored, but I can't figure out why.

Any ideas?

Many thanks,

John McKenzie
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: perl regex works differently within a "do shell script" than from within perl
      • From: Christopher Nebel <email@hidden>
    • Re: perl regex works differently within a "do shell script" than from within perl
      • From: Steve Hayman <email@hidden>
References: 
 >Re: Simple Date-Time Format Question... (From: "Nigel Garvey" <email@hidden>)
 >Re: Simple Date-Time Format Question... (From: kai <email@hidden>)

  • Prev by Date: Excel problems switching between documents
  • Next by Date: Re: Easier way to check for numbered string
  • Previous by thread: Re: Simple Date-Time Format Question...
  • Next by thread: Re: perl regex works differently within a "do shell script" than from within perl
  • Index(es):
    • Date
    • Thread