• 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: Capturing parts of text string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Capturing parts of text string


  • Subject: Re: Capturing parts of text string
  • From: has <email@hidden>
  • Date: Mon, 4 Jul 2005 22:34:59 +0100

Robert Poland wrote:

>Not to "beat a dead horse"...
>(* Strip leading spaces, double spaces and converts "space," to ","
>*)

Dealing with uncertain whitespace padding is absolutely trivial when using regular expressions:

-------

set txt to "   Las Vegas   ,   Nevada 89102
Northbrook,IL    60062
	Las Cruces	,New Mexico		85123-1234   "

tell application "TextCommands"
	set txt to change linebreaks txt to Unix format
	search txt for "^\\s*(.*?)\\s*,\\s*(.*?)\\s+([-0-9]+)\\s*$" with regex and individual line matching
end tell
--> {{"Las Vegas", "Nevada", "89102"}, {"Northbrook", "IL", "60062"}, {"Las Cruces", "New Mexico", "85123-1234"}}

-------

Like I say, regular expressions are a tremendously powerful and invaluable tool, and an absolute must-have for text processing work. It's unfortunate that Apple don't include a regex osax as standard, but there's no shortage of good third-party alternatives. They take a little bit of learning but it's totally worth it, and there's loads of printed and online resources to help; not just tutorials but scads of ready-to-use patterns for all sorts of common tasks too (e.g. finding hyperlinks and email addresses, tidying US phone numbers, etc, etc etc). I can't recommend them enough.

HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Capturing parts of text string
      • From: Tim Mansour <email@hidden>
  • Prev by Date: Re: Address Book comparison
  • Next by Date: Re: Address Book comparison
  • Previous by thread: Re: Capturing parts of text string
  • Next by thread: Re: Capturing parts of text string
  • Index(es):
    • Date
    • Thread