正则菜鸡附上我的方法,不知道是否对楼主有用#include <File.au3>
#include <Array.au3>
Global $file = @ScriptDir & "\test.txt", $search = "HP|Attack"
Global $hFile = FileOpen($file)
If $hFile = -1 Then
MsgBox(0,'ERROR','Unable to open file for reading.')
Exit 1
EndIf
$a = search($search)
MsgBox(0, "", @error ? "查询错误代码:" & @error : $a)
_Exit()
Func search($iSearch)
If $iSearch = "" Then Return SetError(1)
Local $SearchArr = StringSplit($iSearch, "|", 2)
Local $iLine = 1, $sLine = '', $sLine_1 = ''
Local $Return = ''
While 1
$sLine = FileReadLine($hFile, $iLine)
If @error = -1 Then ExitLoop
$sLine_1 = FileReadLine($hFile, $iLine + 1)
_ArraySearch($SearchArr, $sLine)
If @error = 0 Then
$Return &= $iLine & '-' & $sLine & ":" & $sLine_1 & @CRLF
EndIf
$iLine += 2
WEnd
If $Return = "" Then Return SetError(2)
$Return = StringStripWS($Return, 2)
Return SetError(0, "", $Return)
EndFunc
Func _Exit()
FileClose($hFile)
Exit 0
EndFunc
|