• 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: Remove extra spaces from a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remove extra spaces from a string


  • Subject: Re: Remove extra spaces from a string
  • From: John Delacour <email@hidden>
  • Date: Sat, 7 Jun 2003 16:23:47 +0100
  • Mac-eudora-version: 6.0b20

At 1:16 pm +0200 7/6/03, Emmanuel wrote:

If you want to get the things done fast and efficiently and spend your time on something else, then use the regular expressions, an easy advanced string search language made available in AppleScript by the (free) scripting addition "Satimage".

<mini-lecture on regular expressions>

[...]
Which gives, using Satimage osax' "find text" command and assuming x stores the whole string:
-----------------------------
find text "^([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)$" in x using {"\\1", "\\8"} with regexp, string result and all occurrences
-- {{"-rwx------", "demo10.log"}, {"-rwx------", "demo11.log"}, {"-rwx------", "demo12.log"}, {"-rwx------", "demo13.log"}, {"-rwx------", "demo14.log"}}
-----------------------------

that you can rewrite in a more compact form, using the "{n}" notation which repeats the sub-pattern located just before:
-----------------------------
find text "^([^ ]+) +([^ ]+ +){6}([^ ]+)$" in x using {"\\1", "\\3"} with regexp, string result and all occurrences
-----------------------------

Or you could, of course, use perl ... nay, even perl -e :-)


set s to "-rwx------ 0 286 512 Jun 06 12:36 demo10.log
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
-rwx------ 0 286 512 Jun 06 12:40 demo14.log"
set plscr to "for (split $/, " & quoted form of s & ") {
s~.+([A-S])~$1~g ;
s~ [^ ]+$~,$&~g ;
print qq~$_$/~ ; }"
do shell script "perl -e " & quoted form of plscr

--> "Jun 06 12:36, demo10.log
Jun 06 12:37, demo11.log
Jun 06 12:38, demo12.log
Jun 06 12:39, demo13.log
Jun 06 12:40, demo14.log"






.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Remove extra spaces from a string
      • From: Jean-Baptiste LE STANG <email@hidden>
References: 
 >Remove extra spaces from a string (From: Mátyás Ferenc Farkas <email@hidden>)
 >Re: Remove extra spaces from a string (From: Peter Fischer <email@hidden>)
 >Re: Remove extra spaces from a string (From: Emmanuel <email@hidden>)

  • Prev by Date: Bug in iTunes?
  • Next by Date: Re: Strange Bottleneck
  • Previous by thread: Re: Remove extra spaces from a string
  • Next by thread: Re: Remove extra spaces from a string
  • Index(es):
    • Date
    • Thread