#include <GUIConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <IE.au3>
#include <Date.au3>
Global $CurrentInput, $SREMode = 0, $SREFlag = 0, $FileSaved = False
Global $aTime[5]
$MainGUI = GUICreate("字符串正则表达式测试V2", 632, 628)
$HTabMain = GUICtrlCreateTab(5, 15, 620, 200)
$hTab1 = GUICtrlCreateTabItem("测试文字")
$hInput1 = GUICtrlCreateEdit("",10,42, 608, 166)
GUICtrlSetLimit(-1, 1000000)
$CurrentInput = $hInput1
$hTab2 = GUICtrlCreateTabItem("负载测试文件")
$LoadFileButton = GUICtrlCreateButton("打开", 15, 45, 60, 20)
$FileLoadedInput = GUICtrlCreateInput("", 90, 45, 528, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
$hInput2 = GUICtrlCreateEdit("",10,72, 608, 136)
$hTab3 = GUICtrlCreateTabItem("获取网站文字/的HTML")
$WebTextButton = GUICtrlCreateButton("文字", 15, 45, 60, 20)
$WebHTMLButton = GUICtrlCreateButton("HTML", 85, 45, 60, 20)
$WebADDRInput = GUICtrlCreateInput("HTML地址", 160, 45, 458, 20)
$hInput3 = GUICtrlCreateEdit("",10,72, 608, 136)
$hTab4 = GUICtrlCreateTabItem("注明")
$LoadFileButton_Notes = GUICtrlCreateButton("打开", 15, 45, 60, 20)
$SaveFileButton_Notes = GUICtrlCreateButton("保存", 90, 45, 60, 20)
$FileLoadedInput_Notes = GUICtrlCreateInput("", 170, 45, 448, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
$hInput_Notes = GUICtrlCreateEdit(";;; 个人记事本存储;;;" & @CRLF,10,72, 608, 136)
$hTab5 = GUICtrlCreateTabItem("AutoIt")
$LoadFileButton_AutoIt = GUICtrlCreateButton("打开文件", 15, 45, 60, 20)
$SaveFileButton_AutoIt = GUICtrlCreateButton("保存文件", 90, 45, 60, 20)
$OpenInScite_AutoIt = GUICtrlCreateButton("SciTE", 165, 45, 60, 20)
$RunButton_AutoIt = GUICtrlCreateButton("运行脚本", 240, 45, 60, 20)
$RegExButton_AutoIt = GUICtrlCreateButton("代码生成正则表达式", 315, 45, 120, 20)
$hInput_AutoIt = GUICtrlCreateEdit("打开编辑或运行脚本从这里。默认保存位置是在ScriptDir\AutoItCode.au3" & @CRLF,10,72, 608, 136)
GUICtrlCreateTabItem("")
GUICtrlCreateGroup("模式", 5, 217, 620, 67)
$HSRECombo = GUICtrlCreateInput("(.*)", 84, 235, 527, 32)
GUICtrlSetFont(-1, 14, 400, 0, "MS Reference Sans Serif")
GUICtrlSendMsg(-1, $CB_SETEDITSEL, 0, 0)
$ButtonTest = GUICtrlCreateButton("测试", 18, 237, 55, 27, 0)
$HSRERCombo = GUICtrlCreateInput("(.*)", 84, 235, 367, 32)
GUICtrlSetFont(-1, 14, 400, 0, "MS Reference Sans Serif")
GUICtrlSendMsg(-1, $CB_SETEDITSEL, 0, 0)
GUICtrlSetState(-1, $GUI_HIDE)
$HSRERReplace = GUICtrlCreateInput("", 455, 235, 100, 32)
GUICtrlSetFont(-1, 14, 400, 0, "MS Reference Sans Serif")
GUICtrlSendMsg(-1, $CB_SETEDITSEL, 0, 0)
GUICtrlSetState(-1, $GUI_HIDE)
$HSRERCount = GUICtrlCreateInput("0", 565, 235, 50, 32)
GUICtrlSetFont(-1, 14, 400, 0, "MS Reference Sans Serif")
GUICtrlSendMsg(-1, $CB_SETEDITSEL, 0, 0)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("类型", 5, 292, 125, 73)
$HRadioSRE = GUICtrlCreateRadio("StringRegEx", 10, 308, 82, 23)
GUICtrlSetState(-1, $GUI_CHECKED)
$HRadioSRER = GUICtrlCreateRadio("RegExpReplace", 10, 331, 96, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("整数", 5, 370, 125, 138)
$HRadioF0 = GUICtrlCreateRadio("0: True/False", 10, 388, 82, 23)
GUICtrlSetTip(-1, "返回1(匹配)或0(不匹配)")
GUICtrlSetState(-1, $GUI_CHECKED)
$HRadioF1 = GUICtrlCreateRadio("1:Array of matche", 10, 411, 112, 23)
GUICtrlSetTip(-1, "返回数组.")
$HRadioF2 = GUICtrlCreateRadio("2: Array (Perl / PHP)", 10, 433, 112, 23)
GUICtrlSetTip(-1, "返回数组包括充分匹配(的Perl / PHP的风格)")
$HRadioF3 = GUICtrlCreateRadio("3: Global matches", 10, 455, 112, 23)
GUICtrlSetTip(-1, "返回数组.")
$HRadioF4 = GUICtrlCreateRadio("4: A/A (Perl / PHP)", 10, 477, 112, 23)
GUICtrlSetTip(-1, "返回的数组阵列包括完整的数组(的Perl / PHP的样式)")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$HOutput = GUICtrlCreateEdit("", 135, 284, 490, 339)
$Group4 = GUICtrlCreateGroup("返回值", 5, 514, 125, 68)
$Label1 = GUICtrlCreateLabel("@Error", 13, 532, 37, 17)
GUICtrlSetColor(-1, 0x3399FF)
$Label2 = GUICtrlCreateLabel("@Extended", 58, 532, 60, 17)
GUICtrlSetColor(-1, 0x3399FF)
$HError = GUICtrlCreateInput("", 13, 552, 37, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$HExtended = GUICtrlCreateInput("", 62, 552, 52, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ButtonHelp = GUICtrlCreateButton("帮助!", 10, 591, 112, 30, 0)
GUISetState(@SW_SHOW)
While 1
Sleep(20)
If $FileSaved = True And WinActive($MainGUI) = 1 Then
$aTime2 = FileGetTime(@ScriptDir & '\AutoItCode.au3')
$iDateCalc = _DateDiff('s', $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5], $aTime2[0] & "/" & $aTime2[1] & "/" & $aTime2[2] & " " & $aTime2[3] & ":" & $aTime2[4] & ":" & $aTime2[5])
If $iDateCalc >=1 Then
GUICtrlSetData($hInput_AutoIt, FileRead(@ScriptDir & '\AutoItCode.au3'))
$FileSaved = False
Else
$FileSaved = False
EndIf
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $LoadFileButton
$Address = FileOpenDialog("打开一个文件测试", @WorkingDir, "文字相关(*.*)")
If @error <> 1 Then GUICtrlSetData($hInput2, FileRead($Address))
GUICtrlSetData($FileLoadedInput, $Address)
Case $LoadFileButton_Notes
$Address = FileOpenDialog("打开一个文件测试t", @WorkingDir, "文字相关 (*.*)")
If @error <> 1 Then GUICtrlSetData($hInput_Notes, FileRead($Address))
GUICtrlSetData($FileLoadedInput_Notes, $Address)
Case $SaveFileButton_Notes
$Address = FileSaveDialog("保存记录", @WorkingDir, "Text (*.txt)", 16)
If StringRight($Address, 4) <> ".txt" Then $Address &= ".txt"
FileDelete($Address)
FileWrite($Address, GUICtrlRead($hInput_Notes))
Case $LoadFileButton_AutoIt
$Address = FileOpenDialog("打开一个文件测试", @WorkingDir, "文字相关(*.*)")
If @error <> 1 Then GUICtrlSetData($hInput_AutoIt, FileRead($Address))
Case $SaveFileButton_AutoIt
$Address = FileSaveDialog("保存脚本", @WorkingDir, "Au3 (*.au3)", 16)
If StringRight($Address, 4) <> ".au3" Then $Address &= ".au3"
FileDelete($Address)
FileWrite($Address, GUICtrlRead($hInput_AutoIt))
Case $OpenInScite_AutoIt
FileDelete(@ScriptDir & '\AutoItCode.au3')
FileWrite(@ScriptDir & '\AutoItCode.au3', GUICtrlRead($hInput_AutoIt))
ShellExecute(@ScriptDir & '\AutoItCode.au3', "", "", "打开")
$aTime = FileGetTime(@ScriptDir & '\AutoItCode.au3')
$FileSaved = True
Sleep(1000)
Case $RunButton_AutoIt
FileDelete(@ScriptDir & '\AutoItCode.au3')
FileWrite(@ScriptDir & '\AutoItCode.au3', GUICtrlRead($hInput_AutoIt))
ShellExecute(@ScriptDir & '\AutoItCode.au3', "", "", "Run")
Case $RegExButton_AutoIt
If $SREMode = 0 Then
$sPattern = GUICtrlRead($HSRECombo)
GUICtrlSetData($HOutput, "StringRegExp($Value, " & '"' & $sPattern & '"' & ", " & $SREFlag & ")" )
Else
$sPattern = GUICtrlRead($HSRERCombo)
$sReplace = GUICtrlRead($HSRERReplace)
$iCount = GUICtrlRead($HSRERCount)
GUICtrlSetData($HOutput, "StringRegExpReplace($Value, " & '"' & $sPattern & '"' & ", " & '"' & $sReplace & '"' & ", " & $iCount & ")" )
EndIf
Case $HTabMain
If GUICtrlRead($HTabMain) = 0 Then
$CurrentInput = $hInput1
ElseIf GUICtrlRead($HTabMain) = 1 Then
$CurrentInput = $hInput2
ElseIf GUICtrlRead($HTabMain) = 2 Then
$CurrentInput = $hInput3
GUICtrlSetState($WebADDRInput, $GUI_FOCUS)
GUICtrlSendMsg($WebADDRInput, $EM_SETSEL, 0 , 1000)
EndIf
Case $HRadioSRE
$SREMode = 0
GUICtrlSetState($HRadioF0, $GUI_ENABLE)
GUICtrlSetState($HRadioF1, $GUI_ENABLE)
GUICtrlSetState($HRadioF2, $GUI_ENABLE)
GUICtrlSetState($HRadioF3, $GUI_ENABLE)
GUICtrlSetState($HRadioF4, $GUI_ENABLE)
GUICtrlSetState($HSRERCombo, $GUI_HIDE)
GUICtrlSetState($HSRERReplace, $GUI_HIDE)
GUICtrlSetState($HSRECombo, $GUI_SHOW)
GUICtrlSetState($HSRERCount, $GUI_HIDE)
Case $HRadioSRER
$SREMode = 1
GUICtrlSetState($HRadioF0, $GUI_DISABLE)
GUICtrlSetState($HRadioF1, $GUI_DISABLE)
GUICtrlSetState($HRadioF2, $GUI_DISABLE)
GUICtrlSetState($HRadioF3, $GUI_DISABLE)
GUICtrlSetState($HRadioF4, $GUI_DISABLE)
GUICtrlSetState($HSRECombo, $GUI_HIDE)
GUICtrlSetState($HSRERCombo, $GUI_SHOW)
GUICtrlSetState($HSRERReplace, $GUI_SHOW)
GUICtrlSetState($HSRERCount, $GUI_SHOW)
Case $HRadioF0
$SREFlag = 0
Case $HRadioF1
$SREFlag = 1
Case $HRadioF2
$SREFlag = 2
Case $HRadioF3
$SREFlag = 3
Case $HRadioF4
$SREFlag = 4
Case $ButtonTest
SRE()
Case $ButtonHelp
$helppath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1))
ShellExecute("http://www.wutianyu.com/")
If @error = 1 Then MsgBox(0, "错误", "找不到帮助文件")
Case $WebTextButton
_IELoadWaitTimeout(30000)
GUICtrlSetData($hInput3, "请稍候...")
$oIE = _IECreate(GUICtrlRead($WebADDRInput), 0, 0)
If @error = 6 Then
GUICtrlSetData($hInput3, "超时")
Else
GUICtrlSetData($hInput3, _IEBodyReadText($oIE))
EndIf
_IEQuit($oIE)
Case $WebHTMLButton
_IELoadWaitTimeout(30000)
GUICtrlSetData($hInput3, "请稍候...")
$oIE = _IECreate(GUICtrlRead($WebADDRInput), 0, 0)
If @error = 6 Then
GUICtrlSetData($hInput3, "超时")
Else
GUICtrlSetData($hInput3, _IEBodyReadHTML($oIE))
EndIf
_IEQuit($oIE)
EndSwitch
WEnd
Func SRE()
If $SREMode = 0 Then
$sText = GUICtrlRead($CurrentInput)
$sPattern = GUICtrlRead($HSRECombo)
$Regex = StringRegExp($sText, $sPattern, $SREFlag)
$iError = @error
$iExt = @extended
GUICtrlSetData($HError, $iError)
GUICtrlSetData($HExtended, $iExt)
If $SREFlag <=3 Then
$RegExSize = UBound($Regex)
If @error = 1 Then
GUICtrlSetData($HOutput, $Regex)
Else
$OutputString = ""
For $I = 0 To $RegExSize - 1
$OutputString &= "[" & $I & "] = " & $Regex[$I] & @CRLF
Next
GUICtrlSetData($HOutput, $OutputString)
EndIf
Else
$OutputString = ""
For $I = 0 to UBound($Regex) - 1
$match = $Regex[$i]
for $J = 0 to UBound($match) - 1
$OutputString &= "[" & $I & "," & $J & "] = " & $match[$j] & @CRLF
Next
Next
GUICtrlSetData($HOutput, $OutputString)
EndIf
If $iError = 2 Then
GUICtrlSetData($HOutput, "错误的模式\特征" & $iExt - 2 )
GUICtrlSetState($HSRECombo, $GUI_FOCUS)
GUICtrlSendMsg($HSRECombo, $EM_SETSEL, $iExt - 2 , $iExt - 1)
EndIf
Elseif $SREMode = 1 Then
$sText = GUICtrlRead($CurrentInput)
$sPattern = GUICtrlRead($HSRERCombo)
$sReplace = GUICtrlRead($HSRERReplace)
$iCount = GUICtrlRead($HSRERCount)
$sRegExR = StringRegExpReplace($sText, $sPattern, $sReplace, $iCount)
$iError = @error
$iExt = @extended
GUICtrlSetData($HError, $iError)
GUICtrlSetData($HExtended, $iExt)
GUICtrlSetData($HOutput, $sRegExR)
If $iError = 2 Then
GUICtrlSetData($HOutput, "错误的模式\特征" & $iExt - 2 )
GUICtrlSetState($HSRERCombo, $GUI_FOCUS)
GUICtrlSendMsg($HSRERCombo, $EM_SETSEL, $iExt - 2 , $iExt - 1)
EndIf
EndIf
EndFunc