weaponx Posted May 30, 2008 Share Posted May 30, 2008 Dude! It doesn't matter what the name is. The expression retrieves wahtever follows "Full name".Do you see this part?;Delete the following lines when you're done testing$String = ""$String &= "This is a line" & @CRLF$String &= "Full Name Jones, Bob" & @CRLF$String &= "This is another line" & @CRLFThese 4 lines are just to simulate FileRead! Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 (edited) nevermind im good to go.. thanks bud. Edited May 30, 2008 by gcue Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 ya i had done that - but id get an array error.. so i putem back "subscript used with non-array variable" hahah#include <file.au3> ;Search folder $root = @DesktopDir & "\" ;Grab list of txt files $FileList = _FileListToArray($root,"*.txt") ;Loop through text files For $X = 1 to $FileList[0] ;Combine filename with source folder $FileName = $root & $FileList[$X] ;Read file contents $String = FileRead($FileName) ;Find name $array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3) ;If name found, display it If IsArray($array) Then ;Firstname Lastname MsgBox(0,"",$array[1] & " " & $array[0]) ;Dump array to console For $X = 0 to Ubound($array)-1 ConsoleWrite($array[$X] & @CRLF) Next EndIf Next Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 ok works fantastic but now im trying to compare that value from another file for the same person but in the other file the fields are Given Name: Firstname Last Name: Lastname instead of the first file where it was Full Name Lastname, Firstname so i have this (but it doesnt capture the whole firstname nor whole lastname $String = FileRead($file) $nfname = StringRegExp($string,"(?:Given Name:.)(.*).(.*)\r\n",3) MsgBox(0,"",$nfname[0]) $nlname = StringRegExp($string,"(?:Last Name:.)(.*).(.*)\r\n",3) MsgBox(0,"",$nlname[0]) #include <file.au3> ;Search folder $root = @DesktopDir & "\" ;Grab list of txt files $FileList = _FileListToArray($root,"*.txt") ;Loop through text files For $X = 1 to $FileList[0] ;Combine filename with source folder $FileName = $root & $FileList[$X] ;Read file contents $String = FileRead($FileName) ;Find name $array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3) ;If name found, display it If IsArray($array) Then ;Firstname Lastname MsgBox(0,"",$array[1] & " " & $array[0]) ;Dump array to console For $X = 0 to Ubound($array)-1 ConsoleWrite($array[$X] & @CRLF) Next EndIf Next Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 (edited) You need to learn regular expressions because you obviously do not know what you're doing. This is a good site: http://www.regular-expressions.info/tutorial.html. Your expressions should be:$nfname = StringRegExp($string,"(?:Given Name:.)(.*)\r\n",3) $nlname = StringRegExp($string,"(?:Last Name:.)(.*)\r\n",3) Edited May 30, 2008 by zorphnog Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 (edited) expandcollapse popup#include <file.au3> Dim $Name1 = "", $Name2 = "" $Original = FileRead("someotherfile.txt") $array = StringRegExp($Original,"(?:(?:Given Name|Last Name):.)(.*)\r\n",3) ;If name found, display it If IsArray($array) Then $Name1 = $array[1] & " " & $array[0] ;Dump array to console For $X = 0 to Ubound($array)-1 ConsoleWrite($array[$X] & @CRLF) Next EndIf ;Search folder $root = @DesktopDir ;Grab list of txt files $FileList = _FileListToArray($root,"*.txt") ;Loop through text files For $X = 1 to $FileList[0] ;Combine filename with source folder $FileName = $root & "\" & $FileList[$X] ;Read file contents $String = FileRead($FileName) ;Find name $array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3) ;If name found, display it If IsArray($array) Then ;Firstname Lastname $Name2 = $array[1] & " " & $array[0] If $Name2 = $Name1 Then MsgBox(0,"Match","Name1: " & $Name1 & @CRLF & "Name2: " &$Name2) Else MsgBox(0,"No Match","Name1: " & $Name1 & @CRLF & "Name2: " &$Name2) EndIf ;Dump array to console For $X = 0 to Ubound($array)-1 ConsoleWrite($array[$X] & @CRLF) Next EndIf Next Edited May 30, 2008 by weaponx Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 works great. except im getting some spaces on one of the returned values " jones" "bob " any way to get rid of those? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2008 Developers Share Posted May 30, 2008 works great.except im getting some spaces on one of the returned values" jones""bob "any way to get rid of those?Did you check the String functions in the helpfile ?I am sure you can figure this one out yourself. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 Doesn't do it for me. The spaces must be in your text file. I get a match between both files. Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 (edited) Take the tutorial! http://www.regular-expressions.info/tutorial.html$array = StringRegExp($Original,"(?:(?:Given Name|Last Name):\s+)(.*)\r\n",3) Edited May 30, 2008 by zorphnog Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 zorph: im going through the tutorial - thanks =) btw, zorp, i tried ur example and it didnt work either. weapon: yep it is in the text file.. so im trying to get rid of them Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 Well it works for me, unless you have some strange whitespace character. But as @Jos pointed out, there is a simple string function you can use to clear this up. Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 Ok I forgot to take into account whitespace at the end of the name and before the line break. So this would be more fool proof: $array = StringRegExp($Original,"(?:(?:Given Name|Last Name):\s+)([A-Za-z]+).*\r\n",3) Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 got it working perfectly!! thanks a bunch fellas.. the tutorial def helped. Take the tutorial! http://www.regular-expressions.info/tutorial.html $array = StringRegExp($Original,"(?:(?:Given Name|Last Name):\s+)(.*)\r\n",3) 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