d0n Posted June 23, 2009 Posted June 23, 2009 what i am trying to do is to get info from the strings but i ran into some problems 1) i am not sure how to use the "|" function in StringRegExp to get both "hit" and "slash" 2) The name on the 3rd line changes from "You" to "A Tall Dragon", not sure how to have it search for both names Global $i = 1, $name, $dmg While 1 $read = FileReadLine(@scriptdir&"\test.txt", $i) If @error = -1 Then ExitLoop $dmg= StringRegExp($read, "for (\d+)", 1) $name = StringRegExp($read, "(\b\w+\b) hit", 1) If $dmg = 0 Then Else $dmg1 = $dmg[0] $name1 = $name[0] MsgBox("", "Info", $name1 &" = " & $dmg1) EndIf $i = $i + 1 Wend The txt file You slash Dragon for 1183 damage. You hit Dragon for 1217 damage. A Tall Dragon hits you for 96 damage.
Authenticity Posted June 23, 2009 Posted June 23, 2009 Dim $sStr = 'You slash Dragon for 1183 damage.' & @CRLF & _ 'You hit Dragon for 1217 damage.' & @CRLF & _ 'A Tall Dragon hits you for 96 damage.' Dim $sPatt = '(.*?)(?:hit|slashe?)s?.*?for\s*(\d+)' Dim $aLines = StringSplit($sStr, @CRLF, 1) For $i = 1 To $aLines[0] Local $aMatch = StringRegExp($aLines[$i], $sPatt, 1) If UBound($aMatch) = 2 Then ConsoleWrite('Hit: ' & $aMatch[0] & @TAB & 'Dmg: ' & $aMatch[1] & @CRLF) Next
d0n Posted June 23, 2009 Author Posted June 23, 2009 hi one more question, there happens to be a timestamp in front of each line [1:41:21 PM Jun 04 2009] How come this doesn't work? Dim $sPatt = '(]) (.*?)(?:hit|slashe?)s?.*?for\s*(\d+)'
Authenticity Posted June 23, 2009 Posted June 23, 2009 Try using (?i) in the beginning if the pattern because it won't match, right now, HiTs or SlASh or foR, for example: Dim $sStr = '[1:41:21 PM Jun 04 2009] You slash Dragon for 1183 damage.' Dim $sPatt = '(?i)\[[^]]*\]\s*(.*?)(?:hit|slashe?)s?.*?for\s*(\d+)' Dim $aMatch $aMatch = StringRegExp($sStr, $sPatt, 1) If UBound($aMatch) = 2 Then ConsoleWrite('Hit: ' & $aMatch[0] & @TAB & 'Dmg: ' & $aMatch[1] & @CRLF)
d0n Posted June 23, 2009 Author Posted June 23, 2009 thank you for the help, the pattern part is really confusing lol
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