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 |