search for regular expression in text and put the results into an array

Michael Kann mikekann at yahoo.com
Thu Nov 5 14:36:40 EST 2009


The first script that got away didn't count the frequency correctly. This one I hope does so. I also noticed that the other one referred to teams in the scripts and restaurants in the data. I guess I got hungry halfway through the project. I also changed fld "a" to fld "input" and fld "b" to fld "output"

I took out the part where it lists the restaurants as they appear in the raw data. Now you only get the frequency, which was the original intent. 

Sorry if I caused too much trouble with the last script. I'll be more careful in the future.


on mouseUp

put fld "input" into v
put empty into fld "output"

put "<res>" into  aTag
put "</res>" into bTag

replace return with "*" in v
replace aTag with return in v

replace bTag with "@" in v
filter v with "*@*"

set the itemDelimiter to "@"

repeat for each line curLine in v
put item 1 of curLine into curRestaurant
add 1 to frequencyRes[curRestaurant]
end repeat

put "restaurants and frequency" & cr into h
combine frequencyRes with cr and space 
sort frequencyRes numeric descending by last word of each
put h & cr & frequencyRes & cr after fld "output"

end mouseUp


      



More information about the use-livecode mailing list