On Jun 26, 2011, at 08:41, Robert Poland wrote: Since I want to find more than one occurrence I thought the "+" should be on.
I can see how that could be confusing, but this is what the 'allOccurrences' switch is for.
If you set 'allOccurrences' to [FALSE] then only the first pattern match will be found.
I have it set to [TRUE], so every occurrence of the pattern will be found.
Here's a visual example using the same handler as last time:
set str to "Now is the time for all good men to come to the aid of their country..."
# '.' Matches any character. # So with allOccurrences 'true' it finds every individual character in the string:
set foundItems to fnd(".", str, false, true, true) length of foundItems --> 71
# With allOccurrences 'false' it finds only the first instance of the pattern:
set foundItems to fnd(".", str, false, false, true) length of foundItems --> 1
# Here '.+' indicates one or more of any character in sequence:
set foundItems to fnd(".+", str, false, true, true) --> The entire string is matched by the pattern:--> {"Now is the time for all good men to come to the aid of their country..."} length of foundItems --> 1
Your use of "NA" confused me, I thought that was shorthand for Numbers and Alpha.
As you've discovered those are literals. There is shorthand for alphanumerics though. Look for 'POSIX character classes' on this page.
set str1 to "Abraham Lincoln gave his famous Gettysburg Address on Thursday, 11/19/1863."
# Alphanumeric characters == [A-Za-z0-9]: set foundItems to fnd("[[:alnum:]]", str1, false, true, true) length of foundItems --> 62
# Word Characters == '[A-Za-z0-9_]' == Alphanumeric characters plus "_" set foundItems to fnd("[\\w]", str1, false, true, true) length of foundItems --> 62
# OR
set foundItems to fnd("[[:word:]]", str1, false, true, true) length of foundItems --> 62
# Since this string contains an underscore character the count changes by one: set str2 to "Abraham_Lincoln gave his famous Gettysburg_Address on Thursday, 11/19/1863." set foundItems to fnd("[[:word:]]", str2, false, true, true) length of foundItems --> 64
Hopefully this clarifies a few things. Buzz me if you need any other help.
-- Best Regards, Chris
|