Many thanks, Christopher -- it's good to have AS also, since I do have a vague idea of what is going on there! -- A.
On 4 sept. 2012, at 09:48, Christopher Stone wrote: > On Sep 03, 2012, at 01:42, AB <li...@c18.net> wrote: >> Can anyone help with a script or text filter to add a number after a string >> in a file > ______________________________________________________________________ > > Hey AB, > > Kendall's Perl script is far superior for speed with nearly instant > replacement of sample text with 450 replacements. > > Nevertheless it can be done pretty easily with Applescript: > > ------------------------------------------------------------------------- > set regexStr to "\\b(the)\\b" > set _cntr to 0 > tell application "BBEdit" > tell front text window's text > select insertion point before character 1 > repeat > set fndRec to find regexStr options {search mode:grep, > case sensitive:false} > if (found of fndRec) = true then > set _cntr to _cntr + 1 > tell (a reference to found object of fndRec) > set its text to (get its text as text) > & _cntr > end tell > else > exit repeat > end if > end repeat > select insertion point after character -1 > end tell > end tell > ------------------------------------------------------------------------- > > This script however takes about 4 seconds to complete on the same example > text when run from BBEdit's script menu. -- -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to bbedit@googlegroups.com To unsubscribe from this group, send email to bbedit+unsubscr...@googlegroups.com For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>