Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/20/2023 in all areas

  1. Like this? #include <Array.au3> #include <Constants.au3> Local $sFile = _ "125.199.15.243:12324:username:password" & @CRLF & _ "275.111.175.243:12324:username:password" & @CRLF & _ "785.122.125.243:12324:username:password" & @CRLF & _ "385.166.115.243:12324:username:password" & @CRLF & _ "485.144.165.243:12324:username:password" Local $aResult = StringRegExp($sFile, "(.*?):.*:", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult) or when it the start of each line until ":": Local $aResult = StringRegExp($sFile, "(?m)^(.*?):", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult)
    2 points
  2. Too bad I have to wait until I get off work today to examine these!
    2 points
  3. Just an update, to whoever is interested, I worked with security and the application is no longer being blocked.
    2 points
  4. This is a bit more difficult and it's something that I've briefly looked into for some things in my job. In the end I didn't get an actual character count break working, just an occurrence thing. It was set to match a pattern 25 times, then replace it with the match and \n. I'm not quite sure that RegEx can reliably do what you're looking for. That being said, I like trying things and I know more now than I did then, so for commas: https://regex101.com/r/ywFNPy/1 ([^\v]{0,80})(?:,|$) And then for spaces/whitespace it's just a simple modification: https://regex101.com/r/HP6gZy/1 ([^\v]{0,80})(?:\s|$) Putting it into AutoIt to test: Local $s1 = "Marco Scarborough, Chaim Stephenson, Clark Casey, Phoebe Moser, Salena Haley, Cade Batson, Carl Lindsey, Roy Mckenzie, Lillie Peek, Priya Harter, Finn Stratton, Sharon Saxton, Todd Poole, Ariella Findley, Edith Walker" Local $s2 = "There are usually about 200 words in a paragraph, but this can vary widely. Most paragraphs focus on a single idea that's expressed with an introductory sentence, then followed by two or more supporting sentences about the idea. A short paragraph may not reach even 50 words while long paragraphs can be over 400 words long, but generally speaking they tend to be approximately 200 words in length." Local $s3 = $s1 & ' ' & $s2 ConsoleWrite(_WrapText($s1, ",") & @CRLF & @CRLF) ConsoleWrite(_WrapText($s2, " ") & @CRLF & @CRLF) ConsoleWrite('---------------------------------' & @CRLF & @CRLF) ConsoleWrite('RegEx output, Auto:' & @CRLF & _WrapText_RegEx($s3, 0, 80) & @CRLF & @CRLF) ConsoleWrite('RegEx output, comma:' & @CRLF & _WrapText_RegEx($s1, 1, 80) & @CRLF & @CRLF) ConsoleWrite('RegEx output, whitespace:' & @CRLF & _WrapText_RegEx($s2, 2, 80) & @CRLF & @CRLF) Exit Func _WrapText($sTxt, $sChar) Local $iMaxLen = 80 Local $iLen = StringLen($sTxt) Local $sWrapped = "" Local $iStartPos = 1 Local $iRemaining = $iLen While $iRemaining > $iMaxLen Local $iWrapPos = StringInStr(StringMid($sTxt, $iStartPos, $iMaxLen), $sChar, 0, -1) ;~ $sWrapped &= StringMid($sTxt, $iStartPos, $iWrapPos) & "\n" $sWrapped &= StringMid($sTxt, $iStartPos, $iWrapPos) & @CRLF $iStartPos += ($iWrapPos) $iRemaining = $iLen - $iStartPos + 1 If $iRemaining <= $iMaxLen Then $sWrapped &= StringRight($sTxt, $iRemaining) WEnd $sTxt = $sWrapped Return $sTxt EndFunc ;==>_WrapText Func _WrapText_RegEx($sTxt, $iMode = 0, $iLineMaxLength = 80) ; iMode, 0 = Auto, 1 = comma, 2 = whitespace If $iMode = Default Then $iMode = 0 If $iMode > 2 Or $iMode < 0 Then $iMode = 0 If $iLineMaxLength = Default Then $iLineMaxLength = 80 Local $sPatternComma = '([^\v]{0,' & $iLineMaxLength & '})(,|$)' Local $sPatternWhitespace = '([^\v]{0,' & $iLineMaxLength & '})(\s|$)' Local $sPatternAuto = '([^\v]{0,' & $iLineMaxLength & '})(,|\s|$)' Local $sOutput1, $sOutput2, $sReturn Local $aLines1, $aLines2 Local $iLines1, $iLines2 Switch $iMode Case 0 ; Auto, choose whichever produces the least amount of lines, though it may cause lines over 80 characters (when there's not a comma to break on #cs $sOutput1 = StringRegExpReplace($sTxt, $sPatternComma, '$1' & @CRLF) ; Get a count of how many lines there are. Alternatively and likely better is StringReplace for both @LF and @CR and add the @extended $aLines1 = StringSplit($sOutput1, @CRLF, 2) $iLines1 = UBound($aLines1) $sOutput2 = StringRegExpReplace($sTxt, $sPatternWhitespace, '$1' & @CRLF) $aLines2 = StringSplit($sOutput2, @CRLF, 2) $iLines2 = UBound($aLines2) If $iLines1 <= $iLines2 Then $sReturn = $sOutput1 Else $sReturn = $sOutput2 EndIf #ce $sReturn = StringRegExpReplace($sTxt, $sPatternAuto, '$1$2' & @CRLF) Case 1 ; Comma $sReturn = StringRegExpReplace($sTxt, $sPatternComma, '$1$2' & @CRLF) Case 2 ; Whitespace $sReturn = StringRegExpReplace($sTxt, $sPatternWhitespace, '$1$2' & @CRLF) EndSwitch Return StringStripWS($sReturn, 1 + 2) ; $STR_STRIPLEADING + $STR_STRIPTRAILING EndFunc ;==>_WrapText_RegEx Seems to work to me, the only thing is that I'm not keeping the trailing comma or whitespace. It's probably easier to simple add that into the replace with $1,\n, but if you do that make sure that you're adjusting your line/character length -1 for the comma (whitespace one can probably just be dropped). Edit: I just realized that for my 'Auto', I could just combine looking for either a whitespace or a comma, duh. Updated code. Also updated to keep commas, though I don't have a check to make sure that with the comma it doesn't go over 80 characters to 81. Simple way for $iMode = 1 is to set $iLineMaxLength - 1 Edit 2: I also compared the speed of both, and the RegEx is faster: Runs: 100000 1) "_WrapText" ('_WrapText($s2, " ")') time elapsed: 5609.60 ms 2) "_WrapText_RegEx" ('_WrapText_RegEx($s2)') time elapsed: 3541.02 ms #Fastest Function: "_WrapText_RegEx"
    2 points
  5. Uploaded an updated ZIP file which contains a fix for UDF AutoComplete selection not working correctly when the typed word started with underscore.
    1 point
  6. Funny regex challenge My 2 cents Local $s1 = "Marco Scarborough, Chaim Stephenson, Clark Casey, Phoebe Moser, Salena Haley, Cade Batson, Carl Lindsey, Roy Mckenzie, Lillie Peek, Priya Harter, Finn Stratton, Sharon Saxton, Todd Poole, Ariella Findley, Edith Walker" $res1 = StringTrimRight(StringRegExpReplace($s1, ".{1,79}(,|$)\K", "\\n"), 2) Msgbox(0,"", $res1) Local $s2 = "There are usually about 200 words in a paragraph, but this can vary widely. Most paragraphs focus on a single idea that's expressed with an introductory sentence, then followed by two or more supporting sentences about the idea. A short paragraph may not reach even 50 words while long paragraphs can be over 400 words long, but generally speaking they tend to be approximately 200 words in length." $res2 = StringTrimRight(StringRegExpReplace($s2, ".{1,79}(\h|$)\K", "\\n"), 2) Msgbox(0,"", $res2) Edit ...and the func Msgbox(0,"", _WrapText($s1, ",", 80) ) Msgbox(0,"", _WrapText($s2, "\h", 80) ) Func _WrapText($txt, $char, $n) Return StringTrimRight(StringRegExpReplace($txt, '.{1,' & $n-1 & '}(' & $char & '|$)\K', "\\n"), 2) EndFunc Please note that you can write either _WrapText($s2, "\h", 80) or _WrapText($s2, " ", 80) as both work Edit 2 Ooops I didn't see the regex from mistersquirrle... nearly the same
    1 point
  7. -- 2023.03.20 Postgres INSERT UNNEST Example CREATE TABLE IF NOT EXISTS demounnest (dname text, dbday text); TRUNCATE TABLE demounnest; INSERT INTO demounnest (dname, dbday) VALUES ('Abe' -- dname , '1969-07-04') ,('Ben' -- dname , '1979-08-05') ; INSERT INTO demounnest (dname, dbday) SELECT UNNEST(ARRAY['Devon','Earl']) ,UNNEST(ARRAY['1989-01-31','1999-02-28']) ; SELECT * FROM demounnest; -- RESULT "Abe" |"1969-07-04" "Ben" |"1979-08-05" "Devon"|"1989-01-31" "Earl" |"1999-02-28" PostgreSQL: Documentation: 15: 9.19. Array Functions and Operators unnest ( anyarray ) → setof anyelement Expands an array into a set of rows. The array's elements are read out in storage order. unnest(ARRAY[1,2]) → 1 2 unnest(ARRAY[['foo','bar'],['baz','quux']]) → foo bar baz quux The real power of UNNEST is the speed. When we select data from tables we tend to select rows, and insert rows. This is the standard approach. But it is slow. UNNEST, even in this mini example, is 0.25s faster than the conventional insert. UNNEST has been available since before version 9.0 and in 9.15 (Current) UNNEST for SELECT has been expanded.
    1 point
  8. The first post contains the UDF's, which you simply cut&paste into a file yourself.
    1 point
  9. That's correct, I that's what I had originally and I edited to add '\/?', but you're right it isn't needed and I was slightly overthinking it (which is usually where unneeded complications come in ).
    1 point
  10. I think I see now what you're looking to do, you're trying to create a new variable with a dynamic name that's stored in $dynamicVariableName and is: "Setup_" & $iniGroup & "_" & $iniProp. So you're trying to dynamically create the variable $Setup_Main_Path, and you may not know what name you want when you create the script. Honestly this is not something that I do, I usually know what variables I want beforehand. But let me ask this, then, once you've created the global variable $Setup_Main_Path, then what? How are you going to access it, if you don't know the name? With Eval each time? Eval($dynamicVariableName). My question then is... why? Why not just create a variable (array or map maybe) to hold the data that you know the name of? I would recommend checking out Maps in the latest version of AutoIt. They have been added to the stable release: https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm#ArrayMaps This way, you can instead do something like this: ; Declare variables first/at the top of your script. This way they're initialized and you won't try to access them before they exist Global $mDynamicVars[] ; [] - create a Map when you don't set a size or any values (otherwise it will create an array) InitialSetupFile() ConsoleWrite($mDynamicVars["Setup_Main_Path"] & @CRLF) ; Generally in AutoIt functions are put at the bottom of the script. Functions are loaded when the script starts, so they don't need to appear before they're used Func InitialSetupFile() ; Declare your variables first ; It's not a good idea to do delcaration (Local) inside of loops, since you're re-creating the variable each loop Local $defaultValue Local $iniGroup, $iniProp Local $SETOPJSON, $SETOPJSON2 Local $SetupFile = ReadSetupFile() ; You should always declare new variables with the correct scope ;~ Declare all global variables from config File Local $oJson = Json_Decode($JSON_setup) $SETOPJSON = Json_Get($oJson, '.setup') For $i = 0 To UBound($SETOPJSON) - 1 Step 1 $SETOPJSON2 = Json_Get($oJson, '.setup[' & $i & '].values') For $j = 0 To UBound($SETOPJSON2) - 1 Step 1 $iniGroup = Json_Get($oJson, '.setup[' & $i & '].values[' & $j & '].iniGroup') $iniProp = Json_Get($oJson, '.setup[' & $i & '].values[' & $j & '].iniProp') $defaultValue = Json_Get($oJson, '.setup[' & $i & '].values[' & $j & '].defaultValue') ; Create a new map key $mDynamicVars["Setup_" & $iniGroup & "_" & $iniProp] = $SetupFile[$i][$j][3] Next Next EndFunc ;==>InitialSetupFile
    1 point
  11. You already did great with your test, that's why you shouldn't give up your efforts and keep on testing simple patterns. It's the way to improve, slowly, your knowledge with RegEx . I'm feeling same constantly (and probably plenty of users here too) because our knowledge in RegEx is very limited, compared to some gurus on this Forum who can construct quickly powerful patterns. If you don't mind, I would like to discuss your pattern, to eliminate from it what could be superfluous. Here are your original subject & pattern : Leave <anyother> in. This is a string that contains <a id=something>multiple</a> instances of the <a href=another thing>codes</a> that I want to strip out. (</?a[ ].*?>)|(</a>) (In everything that follows, I'll surround with simple quotes every piece of the pattern we're gonna discuss, so it will be clearly visible, for example ' ' for a space or '<a ' for the 3 characters surrounded by the simple quotes. Please think of these simple quotes as 'Forum visual delimiters' , they're not part of the real pattern) You used the pipe symbol '|' which means OR (e.g. named alternation) It's ok with that, because you're searching '<a ...>' or '</a>' So you wanna match the first '<' followed by 'a' followed by 1 space ' ' Then you can simply start your pattern like this, with 3 characters : '<a ' Now you want to grab each and every character until the corresponding closing '>' is found. To do this : => The dot '.' matches any character (except newlines characters by default, we won't discuss it here) => The star quantifier * will repeat the precedent character 0 or more times. => And you want a closing '>' at the end of the match. Then you think : "great, I'll construct my pattern easily ( the part before '|' ) just like this" : '<a .*>' Unfortunately, this didn't work, as you discovered it by yourself (which is great for your knowledge) : This is because the star quantifier '*' is greedy by default. Though it found the 1st closing '>' you were interested in... it kept on searching through the whole subject if there are others '>' . When it found the very last '>' then it matches an endless string starting with the 1st '<a ' and ending with the very last '>' which is not what you want at all. There is a simple way to make the star '*' ungreedy (aka lazy) , it will order the engine to stop searching after it found the very first closing '>' . A question mark '?' placed just after '*' makes the star quantifier ungreedy (as you correctly added it in your original pattern), so now your correct pattern on the left side of the alternation '|' is functional : '<a .*?>' The rest is easy as 1-2-3, a pipe symbol '|' followed by a simple '</a>' '<a .*?>|</a>' This is what this pattern returns (4 matches) before the Replace process : Then you use it directly in the Replace function, replacing all matches with an empty string... $sAfter = StringRegExpReplace($sBefore, '<a .*?>|</a>', '') ...which will correctly output like this : Leave <anyother> in. This is a string that contains multiple instances of the codes that I want to strip out. I hope it's a bit clearer now : no need of groups in your case, e.g. '(...)' or character classes '[ ]' or the optional '/?' as found in your original pattern. Guys, if I wrote something incorrect, please don't hesitate to indicate it. Thanks for reading
    1 point
  12. I couldn't see that, Sorry I had to go i have try on https://file.io/QldDUja24Qng and working to me, I also found the control to send {N} #RequireAdmin #AutoIt3Wrapper_UseX64=y Global $sTestPath, $sTestItem $sTestPath = "\Computer Configuration\Administrative Templates\All Settings" $sTestItem = "Allow Adobe Flash" _Example9($sTestPath, $sTestItem) Func _Example9($sPolicyPath, $sPolicyItem) If Not WinExists("Local Group Policy Editor") Then ;~ ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC") Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Global $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Global $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Global $aPath = StringSplit($sPolicyPath, "\", 1) Global $tmpPath = "" ConsoleWrite("" & @CRLF) For $i = 1 To $aPath[0] $tmpPath &= $aPath[$i] & "|" ConsoleWrite("$tmpPath=" & StringTrimRight($tmpPath, 1) & @CRLF) ControlTreeView($hGPO, "", $hTreeView_1, "Expand", StringTrimRight($tmpPath, 1)) ControlTreeView($hGPO, "", $hTreeView_1, "Select", StringTrimRight($tmpPath, 1)) Sleep(50) Next ;at the bottom tabs we go right to the standard tab ControlFocus($hGPO, "", "AMCCustomTab1") ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Global $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Global $Item, $ItemCnt, $ItemTxt, $FindItem ;Selects the first items. ControlListView($hGPO, "", $hListView, "Select", 0) ;~ ControlSend($hGPO, "", $hListView, "{HOME}") ;Returns a string containing the item index of selected items $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the number of list items. $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount") ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF) Sleep(50) ;Returns the item index of the string. Returns -1 if the string is not found $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) ConsoleWrite("$FindItem=" & $FindItem & @CRLF) Sleep(50) ;Selects the $FindItem items. ControlListView($hGPO, "", $hListView, "Select", $FindItem) ;Returns the text of a given item/subitem. $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3) Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(4097, "--> " & $sPolicyItem, "$FindItem=" & $FindItem & @CRLF & "with Path:" & @CRLF & $ItemTxt & @CRLF & "Pres ok to go step by step") Select Case $iMsgBoxAnswer = 1 ;OK Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect For $x = 0 To $ItemCnt - 1 ControlListView($hGPO, "", $hListView, "Select", $x) $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & " ") $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3) ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF) If $x = $FindItem Then ExitLoop Sleep(100) Next ConsoleWrite("" & @CRLF) $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 0) ConsoleWrite("--> found " & $ItemTxt & @CRLF) ConsoleWrite("" & @CRLF) $iMsgBoxAnswer = MsgBox(4097, "--> " & $sPolicyItem, "$FindItem=" & $FindItem & @CRLF & "with Path:" & @CRLF & $ItemTxt & @CRLF & "Pres ok to find where to send the {N} ? ") Select Case $iMsgBoxAnswer = 1 ;OK Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ControlFocus($hGPO, "", $hTreeView_1) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") WinWait("[TITLE:Microsoft Management Console; CLASS:#32770]") ControlSend("[TITLE:Microsoft Management Console; CLASS:#32770]", "", "Button2", "{N}") EndFunc ;==>_Example9 <image>
    1 point
  13. If it can help, I use it in scripts as Melba23 just indicated, with this code : Case $idRadio_1 $iHow_Choose_img = 1 ; a whole folder (no recursion) using FileSelectFolder() Remove_Style($WS_TABSTOP, $idRadio_1) ; cf note dans F10() , pareil pour tous les autres boutons radios ci-dessous. Case $idRadio_2 $iHow_Choose_img = 2 ; a whole folder + subfolders, using FileSelectFolder() Remove_Style($WS_TABSTOP, $idRadio_2) Case $idRadio_3 $iHow_Choose_img = 3 ; pick files individually, using FileOpenDialog() Remove_Style($WS_TABSTOP, $idRadio_3) ;==================================================== Func Remove_Style($iStyleToRemove, $id1, $id2 = 0, $id3 = 0, $id4 = 0, $id5 = 0, _ $id6 = 0, $id7 = 0, $id8 = 0, $id9 = 0, $id10 = 0) Local $hControl, $iStyle For $i = 1 To @NumParams - 1 ; @NumParams doit être compris entre 2 et 11. Le 1er paramètre sera toujours le style à ôter. $hControl = GUICtrlGetHandle(Eval("id" & $i)) $iStyle = _WinAPI_GetWindowLong($hControl, $GWL_STYLE) If BitAND($iStyle, $iStyleToRemove) = $iStyleToRemove Then _WinAPI_SetWindowLong($hControl, $GWL_STYLE, BitXOR($iStyle, $iStyleToRemove)) Endif Next EndFunc ; Remove_Style() The function can also be called like this (real syntax found in the script) : Remove_Style($WS_TABSTOP, $idRadio_1, $idRadio_2, $idRadio_3, $idRadio_4, $idRadio_11, _ $idRadio_12, $idRadio_13, $idToolTip, $idButton_OK, $idButton_Cancel)
    1 point
  14. Melba23

    Ignore Control in TabOrder

    water, Have you tried removing the $WS_TABSTOP style from the relevant control? It is a default setting when the icon control is created. M23
    1 point
  15. Maybe _GUICtrlEdit_GetCueBanner ?
    1 point
  16. jchd

    _SQLite_Close problem

    It may not be the behavior you expect, but it conforms to the specification (last used handle)... and legacy code.
    1 point
  17. We see a lot of examples submitted by users but rarely do we see threads about good coding practice. Post below if you have an example which exhibits the "dos and don'ts" of coding in AutoIt. Why using Dim over Local/Global is not always a good option: #include <MsgBoxConstants.au3> Dim $vVariableThatIsGlobal = "This is a variable that has ""Program Scope"" aka Global." MsgBox($MB_SYSTEMMODAL, "", "An example of why Dim can cause more problems than solve them.") Example() Func Example() MsgBox($MB_SYSTEMMODAL, "", $vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has "Program Scope" aka Global. Local $vReturn = SomeFunc() ; Call some random function. MsgBox($MB_SYSTEMMODAL, $vReturn, $vVariableThatIsGlobal) ; The Global variable ($vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in "SomeFunc". EndFunc ;==>Example Func SomeFunc() ; This should create a variable in Local scope if the variable name doesn"t already exist. ; For argument sake I totally forgot that I declared a variable already with the same name. ; Well I only want this to be changed in the function and not the variable at the top of the script. ; Should be OK right? Think again. Dim $vVariableThatIsGlobal = "" For $i = 1 To 10 $vVariableThatIsGlobal &= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal. Next Return $vVariableThatIsGlobal EndFunc ;==>SomeFunc
    1 point
×
×
  • Create New...