
Mecano
Active Members-
Posts
66 -
Joined
-
Last visited
Profile Information
-
Location
Netherlands
Mecano's Achievements

Wayfarer (2/7)
0
Reputation
-
mikell, good explanation, as I wrote earlier \K is something new for me. With this fantastic forum and for example SRETester I learn every time something new. Next thing is improve my skills with AutoIt/Microsoft.XML DOM like jdelaney wrote
-
@guinness, "Though the native version could be improved a little bit and the regex version is alot neater" I totally agree with that "Why so? Is it to show off to your coding buddies?" Not at all, just want to learn regex and try to understand the regex I was practicing regex and get stuck, I'm not a regex guru this was no variable enough: $FullPath = "F:\Just a folder\in a another folder\and another\This-dir\And-this-dir" $StringLeft = StringLeft($FullPath, 2) $StringRight = StringRight($FullPath, 21); MsgBox(0, "ShortPath", $StringLeft & "\...\" & $StringRight)So searching for examples I found this topic https://www.autoitscript.com/forum/topic/166301-short-path-anywhere-at-the-string/?do=findComment&comment=1214608 $string = 'regedit.exe /e:a "D:\data\backup\laptop\CCleaner\CCleaner.reg" "HKEY_CURRENT_USER\Software\Piriform\CCleaner"' $short = StringRegExpReplace($string, '("[^\\]+\\)(?:[^\\"]+\\)*([^"]+")', "$1...\\$2") ConsoleWrite($short)Tried to understand the regex, thats why I wrote "you saved my day" K.* was something new for me http://www.regular-expressions.info/keep.html
-
Oh Yeah, mikell you saved my day again boththose, thanks for your contribution, but I need the regex Big thanks for the solution.
-
Hallo Members, I'm looking for a good regex to get the drive letter and the last two folders from a file path, If the path is to long for the label width then show drive + ellipses and two last folders. Drive:\(ellipses)\folder\folder ex. D:\...\folder\folder and when the folder is in the root of the drive then show D:\Folder The test GUI #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Mecano Script Function: ELLIPSIS Long path: Drive:\...\Folder\Folder if root then Drive:\Folder #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $sFile = "F:\Just a folder\in a another folder\and another\This-dir\And-this-dir" $EllipsisPath = StringRegExpReplace($sFile, '\w[a-zA-Z \\]+\\', '') ; <- This needs another regex ;no ellipsis needed, for testing purposes only $sUSB = "K:\Just a folder" $PathforUSB = StringRegExpReplace($sUSB, '\w[a-zA-Z \\]+\\', '') #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Drive + Two last folders of path", 327, 236, 192, 124) $Button1 = GUICtrlCreateButton("Test label", 40, 168, 97, 33) $Label1 = GUICtrlCreateLabel("F:\...\This-dir\And-this-dir", 40, 12, 200, 40) ; <- Looks good but not dynamic GUICtrlSetColor($Label1, 32768) $Label2 = GUICtrlCreateLabel($sFile, 40, 40, 200, 40, $DT_END_ELLIPSIS) ; <- not the last two directorys GUICtrlSetColor($Label2, 16711680) $Label3 = GUICtrlCreateLabel("Var label1", 40, 72, 200, 40) GUICtrlSetColor($Label3, 16711680) $Label4 = GUICtrlCreateLabel("Var label", 40, 104, 200, 40) GUICtrlSetColor($Label4, 16711680) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetData($Label3, $EllipsisPath) ; $DT_END_ELLIPSIS <- works only on GUICtrlCreateLabel GUICtrlSetData($Label4, $PathforUSB) EndSwitch WEnd Thanks in advance
-
jguinch, That's the pattern I need, thank you Solved
-
Mecano reacted to a post in a topic: Regex for password validation
-
jguinch, thanks, your code works, but let say aABbgh@q is now valid too My first question is wrong, sorry The good question must be: at least 1 number and includes both lower and uppercase letters and at least 1 special character
-
ViciousXUSMC, thanks for the answer, both topics I find already and they are very useful, but I need a good pattern. Sorry I forget to tell that € , £ and letters with umlauts, accents, etc. are not allowed. (?=.*\W) this will find any non-word character
-
Hallo members, Looking for the right regex for password validation, the password must be eight characters long including at least 1 number and includes both lower and uppercase letters and at least 1 special character. € , £ and letters with umlauts, accents, etc. are not allowed. I have made a test gui with two different validations, this is just for testing purposes, but is this right way to do it? '((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})'and '([A-Za-z: ]+\$([A-Z0-9]+)([\s]*[A-Za-z: ]+\$([A-Z0-9]+)){0,2})' The test GUI #NoTrayIcon #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Local $GUI, $Password, $Button1, $Button2 $GUI = GUICreate("Form1", 412, 261, 192, 124) $Password = GUICtrlCreateInput("", 96, 32, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD)) GUICtrlSendMsg(-1, $EM_SETCUEBANNER, False, "8 characters") GUICtrlSetLimit(-1, 8, 8) $Button1 = GUICtrlCreateButton("Export", 97, 77, 193, 25) $Button2 = GUICtrlCreateButton("Import", 97, 123, 193, 25) GUISetState(@SW_SHOW) While 1 Local $StringPassw = GUICtrlRead($Password) Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Export If $StringPassw = "" Then MsgBox(16, "Error!", "Password can not be empty") GUICtrlSetState($Password, $GUI_FOCUS) ; regex for testing, the password must be eight characters including one uppercase letter, one special character and alphanumeric characters. ElseIf StringRegExp($StringPassw, '((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})') Then MsgBox(0, "Strong", "Password is 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") ; Debug ; Export() GUICtrlSetState($Button1, $GUI_DISABLE) Else MsgBox(64, "Password is not strong!", "Re-type password, Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") GUICtrlSetData($Password, "") EndIf Case $Button2 ; Import If $StringPassw = "" Then MsgBox(16, "Error!", "Password can not be empty") ; another regex for testing GUICtrlSetState($Password, $GUI_FOCUS) ElseIf StringRegExp($StringPassw, '([A-Za-z: ]+\$([A-Z0-9]+)([\s]*[A-Za-z: ]+\$([A-Z0-9]+)){0,2})') Then MsgBox(0, "Strong", "Password is 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") ; Debug ; Import() GUICtrlSetState($Button2, $GUI_DISABLE) Else MsgBox(64, "Password is not strong!", "Re-type password, Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") GUICtrlSetData($Password, "") EndIf EndSwitch WEnd searched the forum, but good not find a good example Edit; the password must be eight characters long including at least 1 number and includes both lower and uppercase letters and at least 1 special character. € , £ and letters with umlauts, accents, etc. are not allowed. I need only a single regular expression Thanks in advance
-
@jdelaney, gonna give it a try, time to learn AutoIt/Microsoft.XMLDOM Thanks for reply
-
@jdelaney thanx, but see mine openings question. @mikell excellent solution, works perfect never thought of StringRegExpReplace For non-digits can i use this, example: <textversion>False</textversion> $OutlookXML = StringRegExpReplace($OutlookXML, '.*<textversion>(.*)</textversion>.*\R', "")
-
One other question, if I want to remove the line <shortcutInit>0</shortcutInit> or <shortcutInit>1</shortcutInit> whats the correct pattern? This will leave a empty line If StringRegExp($OutlookXML, "(?i)<shortcutInit>0</shortcutInit>") Then $OutlookXML = StringReplace($OutlookXML, '<shortcutInit>0</shortcutInit>', '')
-
Use a part from a function in function
Mecano replied to Mecano's topic in AutoIt General Help and Support
@gritts, The example function (ByteSuffix) is from Spiff59 something like this I'm looking for Return MyProgDir($sMyApp) or Return MyProgDir($sMyAppVer) -
Use a part from a function in function
Mecano replied to Mecano's topic in AutoIt General Help and Support
@gritts, I'm still learning, practicing AutoIt, (kind off solving puzzles). If there was a lynda.com AutoIt video tutorial, I would definitely buy it > Nice example you wrote, going to study this helps me a lot and thanks for explaining Return with the parentheses I hope, practicing and learning won't harm, keeps your brain in top condition Again thanks for the answers Edit: This is a example what I mean _ShowBytes($filesize) instead of call("_ShowBytes") Func MEM() Local $mem = MemGetStats() Local $filesize = $mem[1] Return "Installed memory: " & _ShowBytes($filesize) EndFunc Func _ShowBytes($kbbytes) Local $x, $bytes_suffix[5] = [" KB", " MB", " GB", " TB", " PB"] While $kbbytes > 1023 $x += 1 $kbbytes /= 1024 WEnd Return Round($kbbytes) & $bytes_suffix[$x] EndFunc -
Use a part from a function in function
Mecano replied to Mecano's topic in AutoIt General Help and Support
gritts, good idea arrays But what I mean something like this _MyFunction($MyAppPath, $sMyApp, $sMyAppVer) Let say I make another function, and I want to have some returns from MyProgDir() instead of Call("MyProgDir") I use ($MyAppPath, $sMyApp) it's called ByRef keyword I think Another simple question about parentheses? You have used Return($aSysInfo) with parentheses and not Return $aSysInfo is there rule for it? thnx -
Dear forum members, Filepath, app name and app version in one funtion, which can be use separately, is this possible? example _MyFunction($MyAppPath, $sMyApp, $sMyAppVer); separated to call #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $sMyProgDir Opt("MustDeclareVars", 1) Global $ProgramFilesDir = EnvGet('ProgramFiles(x86)') ; for 64bit Win it will return a valid path. If Not $ProgramFilesDir Then $ProgramFilesDir = @ProgramFilesDir ; for 32bit Win this will "repair" the broken return from above. Local $Gui = GUICreate("My Program info", 343, 197, 192, 124) Local $Button1 = GUICtrlCreateButton("show", 91, 62, 161, 73) GUISetState(@SW_SHOW) While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(4096, "My Program overview", Overview()) ; just for testing purposes EndSwitch WEnd Func Overview() Local $sInfo = _ "OS architecture: " & @OSArch & @CRLF & _ "OS Build: " & @OSBuild & @CRLF & _ "My Program directory: " & MyProgDir() & @CRLF & _ "My Program version: " & MyProgVersion() Return $sInfo EndFunc ;==>Overview ; Func _MyFunction($MyAppPath, $sMyApp, $sMyAppVer); separate to call Func MyProgDir() Local $sRegKey, $iKey, $sHold, $sMyProgRegKey If @OSArch = "X64" Then ;x64 Key $sRegKey = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" Else ;x86 Key $sRegKey = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" EndIf $iKey = 1 While 1 $sHold = RegEnumKey($sRegKey, $iKey) If @error Then ExitLoop $iKey += 1 If RegRead($sRegKey & $sHold, "DisplayName") = 'My Program' Then $sMyProgRegKey = RegRead($sRegKey & $sHold, "InstallLocation") If Not @error Then MsgBox(0, $sHold, $sMyProgRegKey) ;debug ExitLoop EndIf EndIf WEnd If FileExists($sMyProgRegKey) Then $sMyProgDir = StringTrimRight($sMyProgRegKey, 1) MsgBox(0, "Found through REGKey", $sMyProgDir) ;installed with a installer ElseIf FileExists($ProgramFilesDir & "\My Program") Then MsgBox(0, "Found through ProgramFiles Dir", $ProgramFilesDir) ;maybe it's installed with 7-zip, no regkey found $sMyProgDir = $ProgramFilesDir & "\My Program" ElseIf FileExists(@ScriptDir & "\MyProg.exe") Then MsgBox(0, "Found through Script Dir", @ScriptDir) ;maybe it's portable $sMyProgDir = @ScriptDir & "\" Else MsgBox(0, "Not one is true", "What are doing?") ;debug $sMyProgDir = False EndIf ;MsgBox(,"installed:",$sMyProgDir) ; installed location Return $sMyProgDir ;====================== My Program version ================= ;~ If $sMyProgDir = False Then ;~ Return "My Program, not installed" ;~ Else ;~ Local $sMyApp = $sMyProgDir & "\MyProg.exe" ;~ If FileExists($sMyApp) Then ;~ Local $sMyAppVer = StringTrimRight(FileGetVersion($sMyApp), 2) ;~ Return $sMyProgDir & @CRLF & $sMyApp & @CRLF & $sMyAppVer ;~ Else ;~ Return "MyProg.exe not found" ;~ EndIf ;~ EndIf ;=========================================================== EndFunc ;==>_MyProgDir ; separate function for version info Func MyProgVersion() Call("MyProgDir") If $sMyProgDir = False Then Return "My Program, not installed" Else Local $sMyApp = $sMyProgDir & "\MyProg.exe" If FileExists($sMyApp) Then Local $sMyAppVer = StringTrimRight(FileGetVersion($sMyApp), 2) Return $sMyAppVer Else Return "MyProg.exe not found" EndIf EndIf EndFunc ;==>_MyProgVersion Greetings from Holland