Re: Repeating search with GREP
Re: Repeating search with GREP
- Subject: Re: Repeating search with GREP
- From: Andrew Oliver <email@hidden>
- Date: Thu, 27 Mar 2003 12:58:21 -0800
Looking at the Tex-Edit Plus dictionary it would seem that there are (at
least) two ways to achieve this.
The most obvious way would be to simply remove the found text after each
search. That way subsequent searches wouldn't find addresses that have
already been copied since they simply won't exist.
Change the part of your script where you:
>
set theLines to (theLines & selection of window 1 & return)
to:
>
set theLines to (theLines & selection of window 1 & return)
>
cut -- remove the selected text
However, examining the dictionary for 'search', you can see that the other
way is to simply add "finding next" to the search line. This tells Tex-edit
Plus to search from the current selection rather than the beginning of the
file.
>
search window 1 looking for "a" --> always finds first occurrence
But
>
search window 1 looking for "a" finding next --> finds the next occurrence
from the current cursor position.
Andrew
:)
On 3/27/03 12:15 PM, "Blaine Wilson" <email@hidden> wrote:
>
I'm stuck. (As an AS newbie that happens a lot...)
>
>
I'm trying to extract email addresses from a huge text document.
>
>
I've found a grep pattern that works quite well, but I just don't know how
>
to repeat the search. (We'll I've figured out how to repeat it, but it just
>
returns the same result over and over...I want it to move on to the next
>
address after the first hit.)
>
>
Would one of you be so kind as to bestow some insight? Thanks!
>
Here's what I have so far:
>
>
>
copy "" to theLines
>
tell application "Tex-Edit Plus"
>
-- use Tex-Edit to collect all lines containing the string
>
select character 0 of window 1
>
repeat
>
if (search window 1 for
>
"([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA
>
-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)" with whole words and
>
+class SRgp;) is false then
>
exit repeat
>
else
>
set theLines to (theLines & selection of window 1 & return)
>
end if
>
end repeat
>
select character 0 of window 1
>
-- if any lines were found, save them in a new window of Tex-Edit
>
if theLines "" then
>
--set theLines to text 1 thru ((length of theLines) - 1) of theLines
>
activate
>
make new document
>
set text of document 1 to theLines as string
>
else
>
display dialog "No occurences found." buttons {"OK"} default button
>
1 with icon 1
>
return
>
end if
>
end tell
>
>
>
Thanks for your help!
>
>
Blaine
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.