| View previous topic :: View next topic |
| Author |
Message |
kdzialo
Joined: 26 Jun 2009 Posts: 20
|
Posted: Fri Jun 26, 2009 2:40 pm Post subject: Simple? request from a novice |
|
|
What am I doing wrong besides everything
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] |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Fri Jun 26, 2009 3:16 pm Post subject: Re: Simple? request from a novice |
|
|
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) |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
kdzialo
Joined: 26 Jun 2009 Posts: 20
|
Posted: Fri Jun 26, 2009 5:40 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
hutch@edge.net
Joined: 16 Sep 2008 Posts: 77
|
Posted: Fri Jun 26, 2009 6:33 pm Post subject: |
|
|
| Sounds like you are trying to create a spammer for a chat room. Are you? |
|
| Back to top |
|
 |
kdzialo
Joined: 26 Jun 2009 Posts: 20
|
Posted: Fri Jun 26, 2009 6:39 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Fri Jun 26, 2009 7:36 pm Post subject: |
|
|
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 |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
kdzialo
Joined: 26 Jun 2009 Posts: 20
|
Posted: Sat Jun 27, 2009 10:29 am Post subject: |
|
|
Exactly what I needed
Thank you  |
|
| Back to top |
|
 |
|