AutoHotkey Community

It is currently May 26th, 2012, 8:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: June 26th, 2009, 3:40 pm 
Offline

Joined: June 26th, 2009, 3:34 pm
Posts: 20
What am I doing wrong besides everything :wink:

I am trying extract a single line of text in a window to a clipboard...which always begins with the same phrase and is always followed by the same phrase. This single line of text however always changes.

Please help a noob

What I have tried is what you see below:


[code]
WinGetText, text, nameofwindow
clipboard=%text%
Needle = Wow I just
StringGetPos, pos, clipboard, %Needle%
Needle2 = ;Line5
StringGetPos, pos2, clipboard, %Needle2%
Length:=pos2-pos
Clipboard=%SubStr(clipboard, pos [, Length])%
msgbox, %clipboard%


Line1
Line2
Line3
Wow I just found this text
Line5
Line6
Line7[/code]


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 26th, 2009, 4:16 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Perhaps RegEx would be more useful?

Code:
WinGetText, Clipboard, nameofwindow ; you can save directly to Clipboard from the command
MsgBox % RegExReplace(Clipboard,"is).*?(Wow I just[^`n]+).*","$1") ; searches for a pattern starting with 'Wow I just' and matching everything after it that is not a newline (`n)

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 6:40 pm 
Offline

Joined: June 26th, 2009, 3:34 pm
Posts: 20
Thanks that seemed to do the trick....

now how would I could that "found line" to a Clipboard or save it as a named value (i.e. x:=Wow I just found the line....where)?

This is what I tried....for testing purposes.

I copied this phrase to a clipboard "The estimated time left is zero which is of little note but to only me"

with the below code

Haystack:=CLIPBOARD
FoundPos := RegExMatch(Haystack, UnquotedOutputVar = "", "estimat(.*)note",fnd)
msgbox, %fnd1%

I had expected the result to say in a message box:
estimated time left is zero which is of little note

but I got nothing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 7:33 pm 
Offline

Joined: September 16th, 2008, 7:53 pm
Posts: 77
Sounds like you are trying to create a spammer for a chat room. Are you?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 7:39 pm 
Offline

Joined: June 26th, 2009, 3:34 pm
Posts: 20
Nopers....

that would definitely be beyond my abilities.

To clarify what I am trying to accomplish...there are several applications I use at work which I've been using AutoHotKey to make my life easier. A few of these applications do not allow direct text copy/paste abilities, but I have noticed that this text is available using Autoit3 Windows Spy. What I am trying to do is find out a way to capture single lines of text from

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
and
>>>>( TitleMatchMode=slow Hidden Text )<<<<

fields in AWS. The text I'd like to capture is quite often in the same "place" or often follow specific phrases.

Basically I'm trying to make my work life that much easier and learn some AHK at the same time.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 8:36 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
It looks like you might have some things confused about how RegExMatch/RegExReplace works:

Code:
Haystack:=CLIPBOARD


You don't have to pass the Clipboard to a variable named Haystack, Haystack is just a reference for what the variable that goes there represents.

Code:
RegExMatch(Haystack, UnquotedOutputVar = "", "estimat(.*)note",fnd)


RegExMatch wrote:
RegExMatch(Haystack, NeedleRegEx [, UnquotedOutputVar = "", StartingPosition = 1])


You have the fields for UnquotedOutputVar and NeedleRegEx switched in the function and you had already specified fnd as your UnquotedOutputVar:

Code:
RegExMatch(Haystack, "estimat(.*)note",fnd)


Also, when you enclose something in parenthesis in NeedleRegEx that will be a captured subpattern (unless otherwise marked). Based on what you have captured in parenthesis your result will be this:

RegEx result wrote:
ed time left is zero which is of little


The easiest way to capture the whole statement is to remove the parenthesis and fnd will contain your matching pattern:

Code:
RegExMatch(Haystack, "estimat.*note",fnd)
MsgBox % fnd


So let's put it all together:

Code:
Clipboard = The estimated time left is zero which is of little note but to only me

RegExMatch(Clipboard,"estimat.*note",fnd)

MsgBox % fnd

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 11:29 am 
Offline

Joined: June 26th, 2009, 3:34 pm
Posts: 20
Exactly what I needed

Thank you :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, coinman, Exabot [Bot], Google Feedfetcher, oldbrother, Yahoo [Bot] and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group