CaptainCR Posted March 16, 2010 Share Posted March 16, 2010 Hello Everyone,I recently discovered autoit while looking for a way to automate tasks for my employer. I have no real coding/programming experience at all and am looking for ways to speed up production while making some tasks easier for some of my less computer savvy coworkers. We do quite a bit of work with terminal programs here and I'm stuck on trying to extract a changing alphanumeric number from a terminal window. I've looked around the forums for a while now and am trying to determine if StringRegExp is the best/only way to accomplish this. The data is in the following format...AT*AILBA?*AILBA:XXXXXXXXXXXXOKAT*AILVI?*AILVI:OKThe information I'm trying to recover is in Italics. I'm wondering if StringRegExp is the only reliable way to recover this information. The text is always in the structure as displayed if that effects anything. I can accomplish the task using Controlsend and Send commands, but I know how messy and potentially unreliable this can be. I've looked around the forum quite a bit and found the following code posted by Nahuel(thx) in an old thread.$Text=ControlGetText("[CLASS:Notepad]","","[CLASSNN:Edit1]") $Value=StringSplit($Text,@crlf) For $i=1 To $Value[0] If StringRegExp($Value[$i],"[0-9][^:alpha:]") Then MsgBox(0,"",$Value[$i]) EndIf NextThis returns the entire line of text the 12 digit code I'm trying to get in one message box and then the 3rd line down from it in another msgbox after the first. I know my issue is I know nothing about RegEx, but just wonding if I should keep at this or if there is an easier way. Any help would be appreciated.Thanks Link to comment Share on other sites More sharing options...
dani Posted March 16, 2010 Share Posted March 16, 2010 (edited) Instead of looping through that array, I would use this: $Text = "AT*AILBA?" & @CRLF & _ "*AILBA:XXXXXXXXXXXX" & @CRLF & _ "OK" & @CRLF & _ "AT*AILVI?" & @CRLF & _ "*AILVI:" & @CRLF & _ "OK" $Data = StringRegExpReplace($Text, "(?s).*\*AILBA:(.*?)\v+.*", "\1") MsgBox(0, "", $Data) Remember that '& _' notation only allows me to continue the string on the next line without errors from the interpreter. This should be the same string as you would get using ControlGetText() on the Notepad instance. It also works when only the @CR (carriage return) or @LF (line feed) is used as line end character. As long as there is a line end character (which is present if the data in the notepad file is indeed on separate lines as you say). Edited March 16, 2010 by dani Link to comment Share on other sites More sharing options...
CaptainCR Posted March 16, 2010 Author Share Posted March 16, 2010 Instead of looping through that array, I would use this: $Text = "AT*AILBA?" & @CRLF & _ "*AILBA:XXXXXXXXXXXX" & @CRLF & _ "OK" & @CRLF & _ "AT*AILVI?" & @CRLF & _ "*AILVI:" & @CRLF & _ "OK" $Data = StringRegExpReplace($Text, "(?s).*\*AILBA:(.*?)\v+.*", "\1") MsgBox(0, "", $Data) Remember that '& _' notation only allows me to continue the string on the next line without errors from the interpreter. This should be the same string as you would get using ControlGetText() on the Notepad instance. It also works when only the @CR (carriage return) or @LF (line feed) is used as line end character. As long as there is a line end character (which is present if the data in the notepad file is indeed on separate lines as you say). Worked like a charm. I didn't really look at StringRegExpReplace...even so, it would probably taken me forever to figure out how to filter the data. Thanks dani! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now