• 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: looking to correct Smiles measuretext command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: looking to correct Smiles measuretext command


  • Subject: Re: looking to correct Smiles measuretext command
  • From: Robert Poland <email@hidden>
  • Date: Sun, 26 Jun 2011 07:41:35 -0600


On Jun 26, 2011, at 12:35 AM, Christopher Stone wrote:

Hey Bob,

set foundString to fnd("[\s]+", str, true, true, true) -->error

Well.  This suffers from the usual escape issue in Applescript:

 set x to "\" --> error

 set x to "\\"
 log x

--> (*\*)

Although the result you'll see is "\\", this is simply escaping the escape character.  The actual result as you'll see in the Console in Smile is "\" without the quotes.

set str to "Your Broadband2Go Account Number and Programming Instructions"
set foundString to length of fnd("[\\s]", str, false, true, true) --> 6

I had assumed that "\s" had a special meaning as a pair.

Note that '\s' is whitespace and comprises ' ' (space), tabs, returns, and linefeeds.

set str to "Your Broadband2Go Account Number and Programming Instructions.
Topic: Regular Expressions In Applescript"
set foundString to length of fnd("[\\s]", str, false, true, true) --> 12

This one is easy to account for:

set str to "Your Broadband2Go Account Number and Programming Instructions"
set foundString to fnd("[NA ]+", str, true, true, true) --> 6 - should be 18
set stringCount to length of foundString

Remember that the handler call has case-sensitive turned [ON].

Also remember that '+' means one or more.  So if you have one or more of the designated characters in sequence they'll only count as 1 item.  When we remove the '+' sign things work more as you were expecting.  We also need to account for letters of both cases.

Since I want to find more than one occurrence I thought the "+" should be on.

So to get your 18 characters we need to rewrite it thus:

 set foundString to fnd("[nNaA ]", str, true, true, true) --> 18

Your use of "NA" confused me, I thought that was shorthand for Numbers and Alpha.

OR

You could turn off case-sensitive:

 set foundString to fnd("[na ]", str, false, true, true) --> 18

Regular Expressions are finicky and can be confusing - even when you've been using then a long time as I have.  :)

Let me know if you need any more help.

Oh, if you don't have TextWrangler (freeware) please grab a copy, so you'll have a place to test regular expressions.

--
Best Regards,
Chris

End result;
set foundString to fnd("[A-Z0-9\\s]", str, true, true, true)
    gets me what I wanted.

Thanks again,

Robert Poland - Fort Collins, CO



 _______________________________________________
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: looking to correct Smiles measuretext command
      • From: Christopher Stone <email@hidden>
References: 
 >looking to correct Smiles measuretext command (From: Robert Poland <email@hidden>)
 >Re: looking to correct Smiles measuretext command (From: Christopher Stone <email@hidden>)
 >Re: looking to correct Smiles measuretext command (From: Robert Poland <email@hidden>)
 >Re: looking to correct Smiles measuretext command (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: width of column id name column
  • Next by Date: Re: Folder or File?
  • Previous by thread: Re: looking to correct Smiles measuretext command
  • Next by thread: Re: looking to correct Smiles measuretext command
  • Index(es):
    • Date
    • Thread