KaFu Posted May 26, 2009 Share Posted May 26, 2009 (edited) Hiho,those RegExp kill me , here's some sample code:Save as test.au3 in scriptdirexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Example1() Example2() ; example 1 Func Example1() Local $msg GUICreate("My GUI"); will create a dialog box that when displayed is centered GUISetState(@SW_SHOW); will display an empty dialog box ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() EndFunc;==>Example1 ; example 2 Func Example2() Local $gui, $background, $pic, $basti_stay, $msg Local $sFile=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif" $gui = GUICreate("Background", 400, 100) ; background picture $background = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 0, 0, 400, 100) GUISetState(@SW_SHOW) ; transparent MDI child window $pic = GUICreate("", 169, 68, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui) ; transparent pic $basti_stay=GUICtrlCreatePic($sFile, 0, 0, 169, 68) GUISetState(@SW_SHOW) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE EndFunc;==>Example2And here's what I already tried:#include <array.au3> Global $aVars[1] $aVars[0] = 0 $file = FileOpen("test.au3", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Global $aVars[1] $aVars[0] = 0 While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $aMatchesVar = StringRegExp($line, "\$(?i:[A-Z0-9\._%+-]+)", 3); RegEx for Variables If IsArray($aMatchesVar) Then ReDim $aVars[$aVars[0] + UBound($aMatchesVar)] For $n = 0 To UBound($aMatchesVar) - 1 $aVars[$aVars[0] + $n] = $aMatchesVar[$n] Next $aVars[0] = UBound($aVars) - 1 EndIf WEnd _ArrayDisplay($aVars) FileClose($file)- My first goal is to extract a list of variables from test.au3, identified by starting '$' and terminating...yeah, that might be the hard part . The StringRegExp() above captures some, but I would expect a lot more (hell, at least a single) duplicate in the result.- My second goal is to extract a list of function names with a similar StringRegExp(), identified by starting 'Func' and terminating '(' , that you should be easier, though I also fail there I loop by line, so duplicates are no issue. Would be nice, if one of the few with the second sight can give me a helping hand.Best Regards Edited May 26, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 26, 2009 Moderators Share Posted May 26, 2009 Variables: "\$\w+" Functions: "(?i)(?:\A|\n)func\s+(\w+)" Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
KaFu Posted May 26, 2009 Author Share Posted May 26, 2009 Thanks for the reply,Variables:"\$\w+"Functions:"(?i)(?:\A|\n)func\s+(\w+)"but the first captures the same 11 I captured with the RegEx above already, I would expect to have $msg 6 times in the result, but I it there only once. The second RegEx doesnt return anything for me . OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 26, 2009 Moderators Share Posted May 26, 2009 (edited) Thanks for the reply, but the first captures the same 11 I captured with the RegEx above already, I would expect to have $msg 6 times in the result, but I it there only once. The second RegEx doesnt return anything for me .Huh? I got 22 vars returned:#include <array.au3> Local $a = StringRegExp(ClipGet(), "(\$\w+)", 3) _ArrayDisplay($a) ClipGet() obviously used because I didn't want to save the file. Edit: I know these work without testing, because I use them often myself ... Edited May 26, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Mat Posted May 26, 2009 Share Posted May 26, 2009 have you seen valuaters script to show functions etc? HereI'm not sure how he does it, I haven't really looked.MDiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
KaFu Posted May 26, 2009 Author Share Posted May 26, 2009 I got 22 vars returned:#include <array.au3> Local $a = StringRegExp(ClipGet(), "(\$\w+)", 3) _ArrayDisplay($a) Edit: I know these work without testing, because I use them often myself ...I see... me bad, an error in my code , thanks a bunch . $aVars[0] = UBound($aVars) - 1 has to be $aVars[0] = UBound($aVars) I'm not sure how he does it, I haven't really looked.Thanks for the hint. He's doing it by straight string comparison, should also be enough for me . Best Regards OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Authenticity Posted May 26, 2009 Share Posted May 26, 2009 #include <Array.au3> Global $hFile = FileOpen(@ScriptDir & '\test.au3', 0) Global $sSrc Global $aVars, $aFuncs If $hFile = -1 Then Exit MsgBox(0x10, 'Error', '( \/ )' & @LF & '(oO )' & @LF & '(")(")') $sSrc = FileRead($hFile) FileClose($hFile) $sClean = StringRegExpReplace($sSrc, '"(?:[^"]+|"")*"|''(?:[^'']+|'''')*''|;.*', '') $aVars = StringRegExp($sClean, '\$\w+', 3) $aFuncs = StringRegExp($sClean, '(?i)(?x)(\bfunc\s+\w+\s*( \( ( (?>[^()]+) | (?2) )* \) ))', 3) If IsArray($aVars) Then _ArrayDisplay($aVars) If IsArray($aFuncs) Then _ArrayDisplay($aFuncs) 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