Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/13/2023 in all areas

  1. Many ways to do that. My 2 cents ... Local $n = 1 ; 2 ; 3 Local $sRegex = '(?:.*?"data":"([^"]+)"){' & $n & '}' Local $sString = '[[{"records":{"data":"random data"}}],[{"filtered":{"data":"unknown variable"}}],[{"duplicate":{"data":"not constant"}}],{"subject":"Test"}]' Local $res = StringRegExp($sString, $sRegex, 1)[0] Msgbox(0,"", $res) Raw, should include error checking Edit : simpler Local $n = 2 ; 1 ; 3 Local $sRegex = '"data":"([^"]+)"' Local $sString = '[[{"records":{"data":"random data"}}],[{"filtered":{"data":"unknown variable"}}],[{"duplicate":{"data":"not constant"}}],{"subject":"Test"}]' Local $res = StringRegExp($sString, $sRegex, 3) Msgbox(0, "", ($n > UBound($res) OR $n < 1) ? "error" : $res[$n-1])
    3 points
  2. TreeView Extended Styles The MS docu for TreeView extended styles can be found here. Most styles revolve around visual features. This is an implementation of some of these styles: TVS_EX_AUTOHSCROLL Failed to get this style to work. May depend on the TVM_SETAUTOSCROLLINFO message. TVS_EX_DIMMEDCHECKBOXES, TVS_EX_EXCLUSIONCHECKBOXES, TVS_EX_PARTIALCHECKBOXES Depends on the TVS_CHECKBOXES style also being set. The extended CheckBoxes styles must be set before the TVS_CHECKBOXES style. Necessary for the latter to know which extended styles to set. These CheckBoxes look better on Windows 7 than on Windows 10. On Windows 10, some of the state images become very similar. Maybe it's possible to save the state images as icons on Windows 7 and load the icons as new state images on Windows 10. Not tested. TVS_EX_DOUBLEBUFFER The double buffer extended style is usually used to reduce flicker when using the vertical ScrollBar. Therefore, the style is interesting compared to virtual TreeViews. However, it's somewhat uncertain whether the style has any effect at all for these TreeViews, or whether it only works for standard TreeViews. TVS_EX_DRAWIMAGEASYNC Has not been implemented so far. TVS_EX_FADEINOUTEXPANDOS Fade in/out of collapse/expand Buttons when the TreeView control gains/loses focus. Also works better on Windows 7 than on Windows 10. TVS_EX_MULTISELECT According to MS docu this style is not supported. Not implemented. TVS_EX_NOINDENTSTATE No indentation of collapse/expand Buttons. Thus, these Buttons are aligned along the left edge of the TreeView. Failed to get this style to work. TVS_EX_NOSINGLECOLLAPSE Intended for internal use. Not implemented. TVS_EX_RICHTOOLTIP Seems to depend on custom drawn ToolTips. Not implemented. TreeViewExtendedStyles.au3 include #include-once #include <SendMessage.au3> #include <TreeViewConstants.au3> Global Const $TVS_EX_MULTISELECT = 0x0002 Global Const $TVS_EX_DOUBLEBUFFER = 0x0004 Global Const $TVS_EX_NOINDENTSTATE = 0x0008 Global Const $TVS_EX_RICHTOOLTIP = 0x0010 Global Const $TVS_EX_AUTOHSCROLL = 0x0020 Global Const $TVS_EX_FADEINOUTEXPANDOS = 0x0040 Global Const $TVS_EX_PARTIALCHECKBOXES = 0x0080 Global Const $TVS_EX_EXCLUSIONCHECKBOXES = 0x0100 Global Const $TVS_EX_DIMMEDCHECKBOXES = 0x0200 Global Const $TVS_EX_DRAWIMAGEASYNC = 0x0400 Global Const $TVM_SETEXTENDEDSTYLE = $TV_FIRST + 44 Global Const $TVM_GETEXTENDEDSTYLE = $TV_FIRST + 45 Func _GUICtrlTreeView_GetExtendedStyle( $hWnd ) Return IsHWnd( $hWnd ) ? _SendMessage( $hWnd, $TVM_GETEXTENDEDSTYLE ) _ : GUICtrlSendMsg( $hWnd, $TVM_GETEXTENDEDSTYLE, 0, 0 ) EndFunc ; $iExStyle: Extended control styles ; $iExMask: Specifies which styles in $iExStyle are to be affected Func _GUICtrlTreeView_SetExtendedStyle( $hWnd, $iExStyle, $iExMask = 0 ) Local $iRet = IsHWnd( $hWnd ) ? _SendMessage( $hWnd, $TVM_SETEXTENDEDSTYLE, $iExMask, $iExStyle ) _ : GUICtrlSendMsg( $hWnd, $TVM_SETEXTENDEDSTYLE, $iExMask, $iExStyle ) _WinAPI_InvalidateRect( $hWnd ) Return $iRet EndFunc CheckBoxes.au3 example Examples in the Examples\Styles\ folder. Run the examples in SciTE with F5. This is the extended CheckBoxes example, CheckBoxes.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y ; Run script as 64 bit code Opt( "MustDeclareVars", 1 ) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include "..\..\Includes\CreateTreeViewFromSource.au3" #include "..\..\Includes\TreeViewExtendedStyles.au3" CreateTreeViewGui( "TreeViewSource.txt" ) Func CreateTreeViewGui( $sTreeViewSource ) ; Create GUI Local $hGui = GUICreate( "Create TreeView From Source - CheckBoxes", 400, 300, 600, 300, $GUI_SS_DEFAULT_GUI ) ; Create TreeView Local $idTV = GUICtrlCreateTreeView( 2, 2, 396, 296, $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE ) Local $hTV = GUICtrlGetHandle( $idTV ) ; Set CheckBoxes extended styles ; Click CheckBoxes several times to see the different styles _GUICtrlTreeView_SetExtendedStyle( $idTV, $TVS_EX_PARTIALCHECKBOXES+$TVS_EX_EXCLUSIONCHECKBOXES+$TVS_EX_DIMMEDCHECKBOXES ) ; Set CheckBoxes style ; Must be set AFTER extended styles ; Extended CheckBox styles depends on the TVS_CHECKBOXES style also being set. The extended CheckBox styles ; must be set BEFORE the TVS_CHECKBOXES style. Necessary for the latter to know which extended styles to set. DllCall( "user32.dll", "long_ptr", @AutoItX64 ? "SetWindowLongPtrW" : "SetWindowLongW", "hwnd", $hTV, "int", $GWL_STYLE, "long_ptr", _ DllCall( "user32.dll", "long_ptr", @AutoItX64 ? "GetWindowLongPtrW" : "GetWindowLongW", "hwnd", $hTV, "int", $GWL_STYLE )[0] + $TVS_CHECKBOXES ) ; Create TreeView from source file CreateTreeViewFromSource( $hTV, $sTreeViewSource ) _GUICtrlTreeView_Expand( $hTV ) ; Show GUI GUISetState( @SW_SHOW, $hGui ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete( $hGui ) EndFunc The image shows the 5 CheckBoxes on Windows 7 with state image indices 1 - 5: TreeView Explorer Theme Example in the Examples\Theme\ folder. Run the example in SciTE with F5. ExplorerTheme.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y ; Run script as 64 bit code Opt( "MustDeclareVars", 1 ) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <WinAPITheme.au3> #include "..\..\Includes\CreateTreeViewFromSource.au3" CreateTreeViewGui( "TreeViewSource.txt" ) Func CreateTreeViewGui( $sTreeViewSource ) ; Create GUI Local $hGui = GUICreate( "Create TreeView From Source - ExplorerTheme", 400, 300, 600, 300, $GUI_SS_DEFAULT_GUI ) ; Create TreeView Local $idTV = GUICtrlCreateTreeView( 2, 2, 396, 296, $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE ) Local $hTV = GUICtrlGetHandle( $idTV ) ; Set Explorer theme _WinAPI_SetWindowTheme( $hTV, "Explorer", 0 ) ; Create TreeView from source file CreateTreeViewFromSource( $hTV, $sTreeViewSource ) _GUICtrlTreeView_Expand( $hTV ) ; Show GUI GUISetState( @SW_SHOW, $hGui ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete( $hGui ) EndFunc The Explorer theme on Windows 7. Looks better on Windows 10. 7z-file The 7z-file contains source code for UDFs and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. TreeViewStyles.7z
    2 points
  3. Since there were a regex-based solutions here, just for completeness: Of course, it also works purely on a regex-pattern basis: Local $aMatch Local $sString = '[[{"records":{"data":"random data"}}],[{"filtered":{"data":"unknown variable"}}],[{"duplicate":{"data":"not constant"}}],{"subject":"Test"}]' $sString &= $sString & $sString ; first match: $aMatch = StringRegExp($sString, '^.*?"data":\h*"\K[^"]+', 1) ; should also work without "^.*?" because $STR_REGEXPARRAYMATCH is used ConsoleWrite("1st: " & $aMatch[0] & @CRLF) ; nth matches (not including first): For $i = 1 To 20 ; if no xth match then don't output $aMatch = StringRegExp($sString, '(?:"data":.*?){' & $i & '}"data":\h*"\K[^"]+', 1) If Not @error Then ConsoleWrite($i + 1 & "nth: " & $aMatch[0] & @CRLF) Next ; last match: $aMatch = StringRegExp($sString, '"data":\h*"\K[^"]+(?!.+"data")', 1) ConsoleWrite("last: " & $aMatch[0] & @CRLF) However, I think it would be more elegant to returne all matches and then select them by index. Everything else only leads to a higher complexity of the patterns. Or, as I said, treat it as JSON.
    2 points
  4. pixelsearch

    RegExpQuickTester 2.5r

    Hi everybody Here is the script I use to test RegEx patterns offline, it's handy. Credits go to Lazycat, who scripted it initially many years ago and thanked "w0uter for ideas and parts of code". I added some modifications (listed in next post) and would like to thank @jchd @mLipok @mikell @Nine @mistersquirrle @taurus905 and @ioa747 for their contribution. Below are the match text & patterns corresponding to the pic above. For a start, you can copy and paste them in their respective edit control. After you choose the corresponding RegExp mode from the ComboBox at the bottom of the screen (mode 3 = return array of global matches) then you'll have the same results as displayed in the pic above. Match Text : blabla...blabla... blabla..."https://media.pic1.jpg"blabla..."https://media.pic2.png"... blabla..."https://media.pic3.jpg"blabla..."https://media.pic4.png"... blabla...blabla... Pattern : (?i)"([^"]+?\.(?:jpg|png))" When you end the script, 2 files will be created in the same directory of the script. Assuming your script is named "RegExpQuickTester 2.5p.au3", the 2 files created will be : * "RegExpQuickTester 2.5p.txt" which contains the saved Match Text that will be reused when you run the script. * "RegExpQuickTester 2.5p.ini" which contains the saved options that will be reused when you run the script. A right click while hovering over the Edit control of the Search Pattern will display a helpful context menu, with possibility to paste something from the menu inside the Search Pattern. Personally I nearly don't paste anything from the context menu but as this feature was created by the original scripter... Instead I like to consult this context menu as a RegExp syntax reminder ! Anyway, just experiment it and choose what's best for you. 99% of the time, the Search Pattern Tab will be on top. If you notice another colored Tab (except the Personal Tab which will never be highlited), then it means that there is something written in this other tab : the color is here only to remind you that there IS something in this other tab, in case you had forgotten. Even a space or a blank line would color the Tab. YJ This particular design (due to original scripter) won't allow you to type "" in the Replace Pattern Tab (mikell frowned, concerning this missing feature). Gladly I found that typing a non existing group, for example $99 will have the same effect as "" so it's a workaround that seems to do the job. The "Code" button allows you to generate the corresponding AutoIt code, which will be copied to the Clipboard Don't hesitate to ask if you have questions. Our RegExp gurus (that's not me) just love RegExp questions Edit: I forgot. You can drag a text file (or htm etc...) inside the Match Text edit control (it's a droppable zone) . There shouldn't be a 32Kb file size limit anymore as I added code to override this limit. There are probably a couple of other functionalities I'm not thinking of now, you'll easily find what you need if you look at the code. And if you want to modify something in the code, don't hesitate. Just share here your modifications in case other users find them useful too, thanks. Updates are detailed in next post Download last version 11 nov 2024 : RegExpQuickTester 2.5r.au3
    1 point
  5. @Danp2 Hi Dan, YES! That did the trick! Thank you! $sElementSelector = "/html/body/app-root/div/div/app-consumption/div[3]/div[2]/div[6]/div/div/div[4]/div[2]/input" ; Date Input $sElement = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector) ConsoleWrite("Element : " & $sElement & @LF) $sValue = "1.2.2023" _WD_SetElementValue($sSession, $sElement, $sValue, $_WD_OPTION_Advanced)
    1 point
  6. @jugador it's doable with RegEx, if you use Mode 1 (and not 3) #include <Array.au3> Local $aArray, $iOffset = 1, $iMatch = 3 ; <=== change $iMatch value here Local $sRegex = '(?<={"data":)[^\]]+' Local $sString = '[[{"records":{"data":"random data"}}],[{"filtered":{"data":"unknown variable"}}],[{"duplicate":{"data":"not constant"}}],{"subject":"Test"}]' For $i = 1 To 999999999 $aArray = StringRegExp($sString, $sRegex, 1, $iOffset) ; Mode 1 = $STR_REGEXPARRAYMATCH If @error Then Exit MsgBox(0, "Match " & $iMatch, "Nothing found") If $i = $iMatch Then Exit _ArrayDisplay($aArray, "Match " & $iMatch) $iOffset = @extended ; not the best place at all for this line (but ok with this script) Next
    1 point
  7. I fully agree with @AspirinJunkie, if you're going to be using JSON data, use a JSON parser, such as AspirinJunkie's own: However, if you insist on not using it and limiting yourself, I would take a 2 step approach to this example, using _StringBetween() first (assuming you only care about the data in the nested arrays): #include <Array.au3> #include <String.au3> #include <StringConstants.au3> Local $sRegex = '"([^"]*)":"([^"]*)' Local $sString = '[[{"records":{"data":"random data"}}],[{"filtered":{"data":"unknown variable"}}],[{"duplicate":{"data":"not constant"}}],{"subject":"Test"}]' Local $aStringSplit = _StringBetween($sString, '[{', '}]') _ArrayDisplay($aStringSplit) Local $sArrayName = '' For $iMatch = 0 To UBound($aStringSplit) - 1 Local $aArray = StringRegExp($aStringSplit[$iMatch], $sRegex, $STR_REGEXPARRAYMATCH) If UBound($aArray) = 1 Then ContinueLoop $sArrayName = _StringBetween($aStringSplit[$iMatch], '"', '":') If Not @error Then $sArrayName = $sArrayName[0] ConsoleWrite( _ 'Array: ' & $sArrayName & _ ', Key: ' & $aArray[0] & _ ', Value: ' & $aArray[1] & @CRLF) _ArrayDisplay($aArray, $sArrayName) Next Using this approach you can also get the named indexes (records, filtered, duplicate), as you can see on the _ArrayDisplay titles and with _StringBetween($aStringSplit[$iMatch], '"', '":') As for your questions of "stop Regular expression after 1st match", I don't know if that's possible in AutoIt, and I'm not sure why you'd want that. Performance? If so, you could probably get away with doing a simpler check using StringInStr(). For "capture only last match", just use the StringRegExp and in the resulting array do: $aArray[UBound($aArray) - 1]
    1 point
  8. water

    AutoIt Cheat Sheet

    Users are not writing that we shouldn't have a cheat sheet, they are writing that they don't see the benefit of a cheat sheet. So if someone wants to write a CS, feel free!
    1 point
  9. I try my best to continue to be patient in the future @iSan 😅 . Best regards Sven
    1 point
  10. mesale0077 asked me whether I could code some CSS loading animations from different web sites. These are the results using GDI+ (AutoIt v3.3.12.0+ required!): _GDIPlus_MonochromaticBlinker.au3 / _GDIPlus_RotatingBokeh.au3 _GDIPlus_SpinningCandy.au3 / _GDIPlus_SteamPunkLoading.au3 _GDIPlus_IncreasingBalls.au3 / _GDIPlus_PacmanProgressbar.au3 _GDIPlus_StripProgressbar.au3 / _GDIPlus_RingProgressbar.au3 _GDIPlus_LineProgressbar.au3 / _GDIPlus_SimpleLoadingAnim.au3 _GDIPlus_TextFillingWithWater.au3 / _GDIPlus_MultiColorLoader.au3 _GDIPlus_LoadingSpinner.au3 / _GDIPlus_SpinningAndPulsing.au3 _GDIPlus_TogglingSphere.au3 / _GDIPlus_CloudySpiral.au3 _GDIPlus_GlowingText.au3 (thanks to Eukalyptus) / _GDIPlus_HypnoticLoader.au3 _GDIPlus_RotatingRectangles.au3 / _GDIPlus_TRONSpinner.au3 _GDIPlus_RotatingBars.au3 / _GDIPlus_AnotherText.au3 (thanks to Eukalyptus) _GDIPlus_CogWheels.au3 (thanks to Eukalyptus) / _GDIPlus_DrawingText.au3 (thanks to Eukalyptus) _GDIPlus_GearsAnim.au3 / _GDIPlus_LEDAnim.au3 _GDIPlus_LoadingTextAnim.au3 / _GDIPlus_MovingRectangles.au3 _GDIPlus_SpinningAndGlowing.au3 (thanks to Eukalyptus) / _GDIPlus_YetAnotherLoadingAnim.au3 _GDIPlus_AnimatedTypeLoader.au3 / _GDIPlus_Carousel.au3 Each animation function has a built-in example how it can be used. AiO download: GDI+ Animated Wait Loading Screens.7z (previous downloads: 1757) Big thanks to Eukalyptus for providing several examples. Maybe useful for some of you Br, UEZ PS: I don't understand CSS - everything is made out of my mind, so it might be different from original CSS examples
    1 point
  11. nf67, Or you can use these SREs from Malkey to get various parts of the path directly: Local $sFile = "C:\Program Files\Another Dir\AutoIt3\AutoIt3.chm" ; Drive letter - Example returns "C" Local $sDrive = StringRegExpReplace($sFile, ":.*$", "") ; Full Path with backslash - Example returns "C:\Program Files\Another Dir\AutoIt3\" Local $sPath = StringRegExpReplace($sFile, "(^.*\\)(.*)", "\1") ; Full Path without backslash - Example returns "C:\Program Files\Another Dir\AutoIt3" Local $sPathExDr = StringRegExpReplace($sFile, "(^.:)(\\.*\\)(.*$)", "\2") ; Full Path w/0 backslashes, nor drive letter - Example returns "\Program Files\Another Dir\AutoIt3\" Local $sPathExDrBSs = StringRegExpReplace($sFile, "(^.:\\)(.*)(\\.*$)", "\2") ; Path w/o backslash, not drive letter: - Example returns "Program Files\Another Dir\AutoIt3" Local $sPathExBS = StringRegExpReplace($sFile, "(^.*)\\(.*)", "\1") ; File name with ext - Example returns "AutoIt3.chm" Local $sFilName = StringRegExpReplace($sFile, "^.*\\", "") ; File name w/0 ext - Example returns "AutoIt3" Local $sFilenameExExt = StringRegExpReplace($sFile, "^.*\\|\..*$", "") ; Dot Extenstion - Example returns ".chm" Local $sDotExt = StringRegExpReplace($sFile, "^.*\.", ".$1") ; Extenstion - Example returns "chm" Local $sExt = StringRegExpReplace($sFile, "^.*\.", "") MsgBox(0, "Path File Name Parts", _ "Drive " & @TAB & $sDrive & @CRLF & _ "Path " & @TAB & $sPath & @CRLF & _ "Path w/o backslash" & @TAB & $sPathExBS & @CRLF & _ "Path w/o Drv: " & @TAB & $sPathExDr & @CRLF & _ "Path w/o Drv or \'s" & @TAB & $sPathExDrBSs & @CRLF & _ "File Name " & @TAB & $sFilName & @CRLF & _ "File Name w/o Ext " & @TAB & $sFilenameExExt & @CRLF & _ "Dot Extension " & @TAB & $sDotExt & @CRLF & _ "Extension " & @TAB & $sExt & @CRLF) M23
    1 point
×
×
  • Create New...