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
--> (*\*)
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
|