JSThePatriot Posted January 26, 2009 Posted January 26, 2009 (edited) Okay I have been trying to write some Regular Expressions to be sure I can pull out particular sections of a string that change on occasion. TimeCodeDisplay_HH_MM_SS_FF TimeCodeDisplay_MM_SS_FF TimeCodeDisplay_MM_SS Inside "The Regex Coach" the following Regular Expression worked. ((?-i)[HMSF]{2,2}_?){2,4} I tried it in my AutoIt script as follows: This would return MM_SS_FF or MM_SS, it would return blank when the HH_MM_SS_FF was selected. If anyone has some insight as to what I am doing wrong, I would greatly appreciate it. I don't know if I need to use a different Regular Expression checker, but I have checked on http://www.regular-expressions.info/ to be sure my expressions are valid for PCRE, and they are. Thanks in Advance, Jarvis Edited July 21, 2009 by Jon AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Authenticity Posted January 26, 2009 Posted January 26, 2009 #include<Array.au3> Dim $Arr[3] = ['TimeCodeDisplay_HH_MM_SS_FF', 'TimeCodeDisplay_MM_SS_FF', 'TimeCodeDisplay_MM_SS'] Dim $Ret = StringRegExp($Arr[2], '(_HH_MM_SS_FF|_MM_SS_FF|_MM_SS)', 1) _ArrayDisplay($Ret, 'Title') Hope it's correct for the purpose...
ResNullius Posted January 26, 2009 Posted January 26, 2009 ? Dim $Arr[3] = ['TimeCodeDisplay_HH_MM_SS_FF', 'TimeCodeDisplay_MM_SS_FF', 'TimeCodeDisplay_MM_SS'] For $i = 0 To 2 $sRet = StringRegExpReplace($Arr[$i], "(?U-i:.*)(_[HMSF]{2})", "\1") MsgBox(0, "Test", StringTrimLeft($sRet, 1)) Next
evilertoaster Posted January 26, 2009 Posted January 26, 2009 (edited) Hum I was looking at some of the online RegEx checkers and they gave different results sometimes-http://www.regextester.com/http://www.spaweditor.com/scripts/regex/http://regexlib.com/RETester.aspxhttp://www.regextester.com/The stuff you did seems correct I think ( maybe just (HH_MM_SS_FF|MM_SS_FF|MM_SS) would work if they are the only possibilities)...Well there's always StringReplace($a_Value[1],"TimeCodeDisplay_","") Edited January 26, 2009 by evilertoaster
ResNullius Posted January 26, 2009 Posted January 26, 2009 Well there's always StringReplace($a_Value[1],"TimeCodeDisplay_","") Well yeah, but where's the fun in that?
ResNullius Posted January 26, 2009 Posted January 26, 2009 I don't know if I need to use a different Regular Expression checker,Szhlopp's is pretty consistent for AutoIt/PCRE: http://www.autoitscript.com/forum/index.php?showtopic=79685
Robjong Posted January 26, 2009 Posted January 26, 2009 (edited) Hey, heres a couple of ways to do it... #include <Array.au3> ;~ $sRegEx = "\A[^_]+_(.+)" ; as simple as this ;~ $sRegEx = "_([HMSF]{2})" ; simply get changing letters as an array ;~ $sRegEx = "[HMSF]{2}\z" ; simply get the last two letters ;~ $sRegEx = "((?:_[HMSF]{2}){2,4})\z" ; get the whole changing part of the string (or if you just want the last to change {2,4} to {2}) $sRegEx = "_((?:[HMSF]{2}_?){2,4})\z" ; get the whole changing part of the string without leading underscore Dim $Arr[3] = ['TimeCodeDisplay_HH_MM_SS_FF', 'TimeCodeDisplay_MM_SS_FF', 'TimeCodeDisplay_MM_SS'] For $i = 0 To 2 $sRet = StringRegExp($Arr[$i], $sRegEx, 3) If IsArray($sRet) Then _ArrayDisplay($sRet) Next Edit: added regex Edited January 26, 2009 by Robjong
JSThePatriot Posted January 27, 2009 Author Posted January 27, 2009 @Everyone Thanks for the many replies. I find it unfortunate that none of the proposed solutions work except for (HH_MM_SS_FF|MM_SS_FF|MM_SS). That's the only one that worked. The rest wouldn't return an array. I guess I will stick with that solution for now though the point of the RegExp was incase they wanted to add something along the lines of HH_MM_SS, HH_MM to the available formats. Thanks again, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Robjong Posted January 27, 2009 Posted January 27, 2009 (edited) ...I find it unfortunate that none of the proposed solutions work except for (HH_MM_SS_FF|MM_SS_FF|MM_SS)...strange, this one works just as well for me"_((?:[HMSF]{2}_?){2,4})"test scriptexpandcollapse popup#include <Array.au3> Dim $aTimeCodes[5] = ['TimeCodeDisplay_HH_MM_SS_FF', 'TimeCodeDisplay_MM_SS_FF', 'TimeCodeDisplay_MM_SS', 'TimeCodeDisplay_HH_MM_SS', 'TimeCodeDisplay_HH_MM'] Dim $aResults[6][3] = [["Default", "(HH_MM_SS_FF MM_SS_FF MM_SS)", "_((?:[HMSF]{2}_?){2,4})"],["HH_MM_SS_FF", "", ""],["MM_SS_FF", "", ""],["MM_SS", "", ""],["HH_MM_SS", "", ""],["HH_MM", "", ""]] For $i = 0 To 4 $aResults[$i + 1][1] = "" $mRes = StringRegExp($aTimeCodes[$i], "(HH_MM_SS_FF|MM_SS_FF|MM_SS)", 1) If IsArray($mRes) Then $aResults[$i + 1][1] = $mRes[0] Next For $i = 0 To 4 $aResults[$i + 1][2] = "" $mRes = StringRegExp($aTimeCodes[$i], "_((?:[HMSF]{2}_?){2,4})", 1) If IsArray($mRes) Then $aResults[$i + 1][2] = $mRes[0] Next _PrintResults($aResults) _ArrayDisplay($aResults) Func _PrintResults($aArray, $sTitle = "") If Not IsArray($aArray) Then Return SetError(1, 0, 0) ConsoleWrite("-> " & $aArray[0][0] & @CRLF) For $i = 1 To UBound($aArray) - 1 ConsoleWrite($aArray[$i][0] & " ") Next ConsoleWrite(@CRLF & @CRLF) ConsoleWrite("-> " & $aArray[0][1] & @CRLF) For $i = 1 To UBound($aArray) - 1 ConsoleWrite($aArray[$i][1] & " ") Next ConsoleWrite(@CRLF & @CRLF) ConsoleWrite("-> " & $aArray[0][2] & @CRLF) For $i = 1 To UBound($aArray) - 1 ConsoleWrite($aArray[$i][2] & " ") Next ConsoleWrite(@CRLF) EndFunc_PrintResults-> Default HH_MM_SS_FF MM_SS_FF MM_SS HH_MM_SS HH_MM -> (HH_MM_SS_FF MM_SS_FF MM_SS) HH_MM_SS_FF MM_SS_FF MM_SS MM_SS -> _((?:[HMSF]{2}_?){2,4}) HH_MM_SS_FF MM_SS_FF MM_SS HH_MM_SS HH_MMso it seems to return the correct values and would also work on the values you might add, or am i missing something?Edit: code tag Edited January 27, 2009 by Robjong
Moderators SmOke_N Posted January 27, 2009 Moderators Posted January 27, 2009 "(?:_)((?:HH_)*MM_SS(?:_FF)*)" 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.
ResNullius Posted January 28, 2009 Posted January 28, 2009 @EveryoneThanks for the many replies. I find it unfortunate that none of the proposed solutions work except for (HH_MM_SS_FF|MM_SS_FF|MM_SS). That's the only one that worked. The rest wouldn't return an array. I guess I will stick with that solution for now though the point of the RegExp was incase they wanted to add something along the lines of HH_MM_SS, HH_MM to the available formats.Thanks again,JarvisI don't remember seeing where you asked that the results be an Array
Authenticity Posted January 28, 2009 Posted January 28, 2009 ...Inside "The Regex Coach" the following Regular Expression worked. I tried it in my AutoIt script as follows:$a_Ret = StringRegExp($a_Value[1], "((?-i)[HMSF]{2,2}_?){2,4}", 1)Then I think you've missed that the last parameter is 1, heh. Took me too some time to understand the purpose lol.
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