Hyflex Posted June 3, 2013 Share Posted June 3, 2013 (edited) Basically, I have a counter which counts down and i'm trying to get the time left in milliseconds... Potential string formats: Updates in: x hours xx minutes Updates in: x hours xx minutes Updates in: xx minutes xx seconds Updates in: xx minutes xx seconds Updates in: xx seconds Updates in: x seconds I've been trying a few things but none are working :/ $sResults = StringRegExp("Updates In: 22 hours, 13 minutes",'<b>Updates In:(.*)</b>',3) $sSingleResult = $sResults[0] If StringRegExp($sSingleResult, "hours") Then ConsoleWrite(StringRegExp($sSingleResult, "(.*?)hours") & @CRLF) $hours = True EndIf If StringRegExp($sSingleResult, "minutes") Then ConsoleWrite(StringRegExp($sSingleResult, "minutes") & @CRLF) $minutes = True EndIf If StringRegExp($sSingleResult, "(.*?) seconds") Then ConsoleWrite(StringRegExp($sSingleResult, "(.*?)seconds") & @CRLF) $seconds = True EndIf If StringMid($sSingleResult, 4, 5) = "hours" Then $HoursIntoMiliseconds = StringMid($sSingleResult, 2, 1) * 3600000 $MinutesIntoMiliSeconds= StringMid($sSingleResult, 11, 2) * 60000 $TotalTime = $HoursIntoMiliseconds + $MinutesIntoMiliSeconds Else $MinutesIntoMiliSeconds = StringMid($sSingleResult, 2, 2) * 60000 EndIf Edited June 3, 2013 by Hyflex Link to comment Share on other sites More sharing options...
jdelaney Posted June 3, 2013 Share Posted June 3, 2013 (edited) try this out: $string = "Updates in: 12 hours 12 minutes" $array = StringRegExp($string, "(\d+)\s(\w+)", 4) $iMilli = 0 For $i = 0 To UBound($array)-1 $aTemp = $array[$i] Switch $aTemp[2] Case "hours" $iAddition = $aTemp[1]*(60*60*1000) Case "minutes" $iAddition = $aTemp[1]*(60*1000) Case "seconds" $iAddition = $aTemp[1]*(1000) Case Else MsgBox(1,1,"this one is not a covered 'Case'...add it in, and re-run=[" & $aTemp[2] & "].") $iAddition = 0 EndSwitch $iMilli += $iAddition Next ConsoleWrite($iMilli & @CRLF) Edited June 3, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Hyflex Posted June 3, 2013 Author Share Posted June 3, 2013 (edited) Works beautifully, I don't quite understand how you achieved that... Could you explain how that was done, it's something to do with the regexp I assume. Edited June 3, 2013 by Hyflex Link to comment Share on other sites More sharing options...
jdelaney Posted June 3, 2013 Share Posted June 3, 2013 (edited) just looking for digits followed by letters. Each grouping found is returned into it's own array (that's the option 4 on stringregexp)...then i loop through those returned groups, switch out based on the string, multiply, and add onto a variable. Edit: I just added a fail checker as well... Edited June 3, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
guinness Posted June 4, 2013 Share Posted June 4, 2013 There is also this site, which is a cheat sheet for regular expressions. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Zedna Posted June 4, 2013 Share Posted June 4, 2013 @jdelaney Very nice example for using StringRegExp() with mode 4! This should be as example in Helpfile for StringRegExp() Resources UDF ResourcesEx UDF AutoIt Forum Search 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