正则测试

 

#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

Regex Testor Version 1.02 Copyright (c) 2013 Fiery Red - flameleo 我们在使用正则表达式( regex: regular expression )的过程中,经常发现正则表达式的语法很令人头疼,即使对经常使用它的人来说也是如此。对于刚接触正则表达式的人来说多练习,多使用,才能熟练掌握正则表达式。 由于难于读写,容易出错,且需要反复练习。所以找一种工具对正则表达式对我们脑中构思的regex进行测试是很有必要的。 1.特点 a.适合初学者,在不断测试用学习如何使用正则表达式。 b.可以分组保存,测试中用到的正则表达式。 c.本工具使用最常见的regex。以下是简单示例: a|b Matches a or b gr(a|e)y Matches a or e . Matches any single character [abc] Matches a single character a, b or c [^abc] Matches any single character except a, b or c [a-z] Matches a single charactor in the range a to z [a-zA-Z] Matches a single charactor in the range a to z or A to Z ^ Matches the start of the filename $ Matches the end of the filename * Matches the preceding element zero or more times ? Matches the preceding element zero or one times + Matches the preceding element one or more times {x} Matches the preceding element x times {x,} Matches the preceding element x or more times {x,y} Matches the preceding element between x and y times 值得一提的是()代表子匹配,有些环境中gr(a|e)y Matches gray or grey 还支持许多常见的转义字符 \b,\B,\c,\d,\D,\f,\n,\r,\s,\S,\t,\v,\w,\W,\x,\u 具体详见附件 Regular Expression Syntax1.html 2.功能介绍 a.界面上显示提供regex输入框和原文本框,点击[模式匹配]按钮后,会在右侧输出结果,包括匹配字符串列表和文本。 b.对于测试中一些有用的regex,点击[insert]按钮添加到模式列表,以备日后使用。你可以位该regex添加描述分组,该信息会在程序结束后保存在CustomPatternInfo.ini文件中。 c.可以参考Readme_1.jpq和Readme_2.jpq图片介绍。 3.有待改进 a.界面布局和控件友好型和交互性。 b.界面功能提供regex语法支持。(暂时可以通过导入附件RegexSystax.ini到CustomPatternInfo.ini中) 4.意见反馈 a.请将您的宝贵意见反馈到 FieryRed_2012@163.com 附件: Readme.txt Readme_1.jpg Readme_2.jpg Regular Expression Syntax.html RegexSystax.ini
Elasticsearch是一个基于Lucene的开源搜索引擎,它支持全文检索和实时分析。在Elasticsearch中,正则测试主要用于对文本进行模式匹配和提取特定内容。通过使用正则表达式,我们可以在一大段文本中快速地定位符合特定模式的内容,从而实现更精确的信息提取和搜索。 正则表达式是一种强大的文本匹配工具,它可以用来描述字符的模式,包括字符集合、重复、位置和逻辑操作等。在Elasticsearch中,我们可以利用正则表达式来进行模式匹配查询,从而实现对文档中的内容进行精准匹配和提取。 在实际应用中,我们可以通过使用Elasticsearch的正则测试功能,编写符合特定需求的正则表达式,并对目标文档进行测试。比如,我们可以使用正则表达式来匹配邮件地址、电话号码、URL等特定格式的文本,或者提取文档中特定的关键词、ID等内容。 通过Elasticsearch的正则测试功能,我们可以快速验证和调试正则表达式的准确性和效率,从而更好地应用于实际的搜索和分析任务中。正则测试功能可以帮助我们更准确地定位和提取文档中的内容,提高搜索效率,为数据分析和挖掘提供更多的可能性。 总之,Elasticsearch的正则测试功能为我们提供了一个方便快捷的工具,可以有效地支持对文本数据的模式匹配和信息提取,为我们的搜索和分析工作提供更多可能性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值