water Posted January 17, 2019 Share Posted January 17, 2019 (edited) For my iCal UDF I need to translate rfc 2445 duration format to an array holding the possible values (week, day, hour, minute, second): Has anyone already written some code to to this? Quote 4.3.6 Duration Value Name: DURATION Purpose: This value type is used to identify properties that contain a duration of time. Formal Definition: The value type is defined by the following notation: dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week) dur-date = dur-day [dur-time] dur-time = "T" (dur-hour / dur-minute / dur-second) dur-week = 1*DIGIT "W" dur-hour = 1*DIGIT "H" [dur-minute] dur-minute = 1*DIGIT "M" [dur-second] dur-second = 1*DIGIT "S" dur-day = 1*DIGIT "D" Description: If the property permits, multiple "duration" values are specified by a COMMA character (US-ASCII decimal 44) separated list of values. The format is expressed as the [ISO 8601] basic format for the duration of time. The format can represent durations in terms of weeks, days, hours, minutes, and seconds. No additional content value encoding (i.e., BACKSLASH character encoding) are defined for this value type. Example: A duration of 15 days, 5 hours and 20 seconds would be: P15DT5H0M20S A duration of 7 weeks would be: P7W "P15DT5H0M20S" should be translated to [0, 15, 5, 0, 20] ; week, day, hour, minute, second Some RegExp guru around? Any help is greatly appreciated Edited January 17, 2019 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted January 17, 2019 Share Posted January 17, 2019 Hmm. As I don't know which letters are mandatory in the expression and which expressions are allowed I'm not sure of the result... So here is a raw try. The returned array will always be 5 elements [ week, day, hour, minute, second ] #Include <Array.au3> $d = "P15DT5H0M20S" ;$d = "P7W" ;$d = "PT1H" ;$d = "P15DT30M" $res = StringRegExp($d, 'P(?:(\d*)W)?(?:(\d*)D)?T?(?:(\d*)H)?(?:(\d*)M)?(?:(\d*)S?)', 3) _ArrayDisplay($res) Link to comment Share on other sites More sharing options...
seadoggie01 Posted January 17, 2019 Share Posted January 17, 2019 First, I'm amazed! (I tried this for a bit, but it was a bit too complicated for a newbie regex-er) Second, I think the P is optional? I thought it referenced whether the value was positive or not... but I'm not sure Third, can you explain what the difference between using a 3 flag and a 1 flag is? They seem to return the same thing All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 17, 2019 Share Posted January 17, 2019 (edited) @mikell Since seems that the P is mandatory, you can "capture" the other letters in order to know at which parameter is "assigned" the value previousely "captured" @water You could use something like this: Func _RFC2445Conversion($strRawDuration) Local $arrResult, _ ; Array used to store the "capture(s)" from SRE $arrReturn[1][2] ; Array in which are stored "tidely" the various values, in the format Property|Value ; Store the result of the "capture(s)" in the array, which is going to be processed later $arrResult = StringRegExp($strRawDuration, "^(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$", $STR_REGEXPARRAYMATCH) ; [-+]? ;_ArrayDisplay($arrResult) ; Add the various "capture(s)" in the array that will be returned For $i = 0 To UBound($arrResult) - 1 Step 1 If $arrResult[$i] <> 0 Then _ArrayAdd($arrReturn, StringRegExpReplace($arrResult[$i], "(\d+)([WDHMS])", "$2|$1")) Next ; This, or delete the first element of the array (which will always be blank) $arrReturn[0][0] = "Raw Duration" $arrReturn[0][1] = $strRawDuration Return $arrReturn In case you have only one Duration: Spoiler #include <Array.au3> Global $strDuration = "P15DT5H0M20S" _ArrayDisplay(_RFC2445Conversion($strDuration)) In case you have multiple Durations, delimited by a comma: Spoiler #include <Array.au3> Global $strDuration = "P15DT5H0M20S, P7W, PT1H, P15DT30M", _ $arrDurations $arrDurations = StringSplit($strDuration, ", ", $STR_ENTIRESPLIT) For $i = 1 To $arrDurations[0] Step 1 _ArrayDisplay(_RFC2445Conversion($arrDurations[$i])) Next If you could tell us what is the sign - or + used for, it can be inserted in the pattern in order to be "captured" as well @seadoggie01 The difference between Flag 1 and 3 is that the first returns from the function after the first "match", and the second continues trying to "match" the pattern all over the rest of the string. Something like this: Spoiler #include <Array.au3> Global $strDuration = "P15DT5H0M20S" _ArrayDisplay(StringRegExp($strDuration, "^(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$", $STR_REGEXPARRAYMATCH), "$STR_REGEXPARRAYMATCH") Global $strDuration = "P15DT5H0M20S, P0DT1H2M3S" _ArrayDisplay(StringRegExp($strDuration, "(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)", $STR_REGEXPARRAYGLOBALMATCH), "$STR_REGEXPARRAYGLOBALMATCH") Edited January 17, 2019 by FrancescoDiMuro seadoggie01 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
TheXman Posted January 18, 2019 Share Posted January 18, 2019 (edited) Here's my suggestion: expandcollapse popup#include <Constants.au3> #include <Array.au3> _ArrayDisplay(rfc2445_duration("+P7W") , "+P7W") _ArrayDisplay(rfc2445_duration("+P7W5D") , "+P7W5D") _ArrayDisplay(rfc2445_duration("+P7W5D6H") , "+P7W5D6H") _ArrayDisplay(rfc2445_duration("+P7W5D6H2M") , "+P7W5D6H2M") _ArrayDisplay(rfc2445_duration("+P7W5D6H2M6S"), "+P7W5D6H2M6S") Func rfc2445_duration($sRfc2445Duration) Enum $WEEK, $DAY, $HOUR, $MIN, $SEC Local $aDuration[5], _ $aResult Local $iDuration = 0 ;Get week $iDuration = 0 $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)W", $STR_REGEXPARRAYMATCH) If IsArray($aResult) Then $iDuration = $aResult[0] $aDuration[$WEEK] = $iDuration ;Get day $iDuration = 0 $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)D", $STR_REGEXPARRAYMATCH) If IsArray($aResult) Then $iDuration = $aResult[0] $aDuration[$DAY] = $iDuration ;Get hour $iDuration = 0 $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)H", $STR_REGEXPARRAYMATCH) If IsArray($aResult) Then $iDuration = $aResult[0] $aDuration[$HOUR] = $iDuration ;Get min $iDuration = 0 $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)M", $STR_REGEXPARRAYMATCH) If IsArray($aResult) Then $iDuration = $aResult[0] $aDuration[$MIN] = $iDuration ;Get secs $iDuration = 0 $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)S", $STR_REGEXPARRAYMATCH) If IsArray($aResult) Then $iDuration = $aResult[0] $aDuration[$SEC] = $iDuration Return $aDuration EndFunc Edited January 18, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
water Posted January 18, 2019 Author Share Posted January 18, 2019 Thanks a lot for your replies. I will test as soon as I find some spare time. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 18, 2019 Author Share Posted January 18, 2019 @mikell Quote dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week) I interpret "+" and "-" to be optional, "P" as mandatory. I just tested your solution and it works great Thanks to all other users for their effort to help me solve my problem My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 19, 2019 Author Share Posted January 19, 2019 On 17.1.2019 at 11:39 PM, FrancescoDiMuro said: If you could tell us what is the sign - or + used for, it can be inserted in the pattern in order to be "captured" as well The sign - or + is used to tell if the duration should be added (e.g. to calculate the end date-time of an event) or subtracted (e.g. when the alarm for an event should go off). Now the result has 5 elements (for week, day, hour, minute and second). I would be glad if you could modify the RegExp to add the +/- sign so we get (plus/minus, week, day, hour, minute and second). Thanks a lot for your support! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 19, 2019 Share Posted January 19, 2019 (edited) @water ^(?:([-+])?P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$ This RegEx returns an array of 6 elements, which are: Plus/minus sign; Week(s); Day(s); Hour(s); Minute(s); Second(s). Each field is optional, except the P, which has always to be in the string in that exact position. The RegEx could returns a more precise result if each field has ranges too (for example, Week parameter goes from 1 to N, and so on). Try it, and let us know Edited January 20, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted January 19, 2019 Share Posted January 19, 2019 It works using a slight variation of my previous expression - but will it be easier for you than a simple StringLeft($string, 1) ? #Include <Array.au3> ;$d = "P15DT5H0M20S" ;$d = "P7W" ;$d = "+PT1H" $d = "+P15DT30M" $res = StringRegExp($d, '([+-]?)P(?:(\d*)W)?(?:(\d*)D)?T?(?:(\d*)H)?(?:(\d*)M)?(?:(\d*)S?)', 3) _ArrayDisplay($res) @FrancescoDiMuro I guess that you didn't test your expression against the various possibilities I mentioned in my snippet Link to comment Share on other sites More sharing options...
water Posted January 19, 2019 Author Share Posted January 19, 2019 Thanks a lot for the updated expression! 15 minutes ago, mikell said: but will it be easier for you than a simple StringLeft? I fear it would take a lot of ordinary AutoIt code to split this string. Having a one line RegExp makes it fast and short I will have a reference to this thread in the iCal UDF so that everyone knows who wrote it and how it works My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 19, 2019 Author Share Posted January 19, 2019 Quote The RegEx could returns a more precise result if each field has ranges too (for example, Week parameter goes from 1 to N, and so on). I assume that the ics file has a valid format so your regular expressions are exactly what I need My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 19, 2019 Share Posted January 19, 2019 (edited) @mikell Try your pattern on this string and tell us what is returned: +P15DT30 It will fail since you can't assume that the last \d* is effectively the S(Seconds(s)) parameter, and indeed it is "captured" as it is, even if it's not (it should be hours taking the order of the string).@water It depends from what do you want to manage: a 1-Dimensional array, a 2-Dimensional array, or a string in which you have Sign="", W="", D="15", and so on... This function returns a string of what is being effectively "captured" from the string you pass to it, so, no pre-sized arrays are filled: ConsoleWrite(_RFC2445Conversion("+P15DT5H0M20S") & @CRLF) ; Sign = +, D = 15, H = 5, M = 0, S = 20 ConsoleWrite(_RFC2445Conversion("+P7W") & @CRLF) ; Sign = +, W = 7 ConsoleWrite(_RFC2445Conversion("+PT1H") & @CRLF) ; Sign = +, H = 1 ConsoleWrite(_RFC2445Conversion("+P15DT30M") & @CRLF) ; Sign = +, D = 15, M = 30 ConsoleWrite(_RFC2445Conversion("-15DT30M") & @CRLF) ; Doesn't return anything ConsoleWrite(_RFC2445Conversion("+P15DT30") & @CRLF) ; Doesn't return anything Func _RFC2445Conversion($strRawDuration) Local $arrResult, _ ; Array used to store the "capture(s)" from SRE $strDuration = "" ; Variable used to return the Duration ; Store the result of the "capture(s)" in the array $arrResult = StringRegExp($strRawDuration, "^([-+])P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?$", $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then $strDuration = "Sign = " & $arrResult[0] & ", " For $i = 1 To UBound($arrResult) - 1 Step 1 If $arrResult[$i] <> "" Then If $i < UBound($arrResult) - 1 Then $strDuration &= StringRight($arrResult[$i], 1) & " = " & StringRegExp($arrResult[$i], "^(\d+)(?:[WDHMS])$", 1)[0] & ", " Else $strDuration &= StringRight($arrResult[$i], 1) & " = " & StringRegExp($arrResult[$i], "^(\d+)(?:[WDHMS])$", 1)[0] EndIf EndIf Next EndIf Return $strDuration EndFunc P.S.: Since you've said that the sign is used to add or subtract the time period, then it automatically became mandatory Edited January 19, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted January 19, 2019 Share Posted January 19, 2019 5 minutes ago, FrancescoDiMuro said: +P15DT30 It will fail since you can't assume that the last \d* is effectively the seconds, and indeed it is "captured" as seconds, even if it's not (it should be hours). Right. I don't know the RFC 2445 format, so based on the syntax definition that water provided in post #1 I assumed that the letters are mandatory after each concerned number - so +P15DT30 could not be a valid RFC 2445 duration to be treated BTW this StringRegExp("+PT1H", '^([-+])P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?$', 3) does not return a 6 elements array (required) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 19, 2019 Share Posted January 19, 2019 2 minutes ago, mikell said: (required) Let's see what @water says Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted January 19, 2019 Author Share Posted January 19, 2019 The RFC 5545 specification for the duration can be found here: https://tools.ietf.org/html/rfc5545#page-35 The formal grammar for the content type is based on the Internet ABNF defined in RFC 5234. My understanding is: + and - are optional Letter "P" is mandatory letters are mandatory after each concerned number "1*DIGIT" in the specification stands for 1 or multiple digits So "-15DT30M" should be "-P15DT30M" and "+P15DT30" should be "+P15DT30M". Thanks a lot for your assistance! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 19, 2019 Share Posted January 19, 2019 (edited) @water The following script returns an array of six elements, ordered in this way: Array element #0 = Sign; Array element #1 = Week(s); Array element #2 = Day(s); Array element #3 = Hour(s); Array element #4 = Minute(s); Array element #5 = Second(s). The script controls if the passed string has the format required by the RFC2445 specification, and then process it, extracting all the parameters as it is stated above. #include <Array.au3> #include <StringConstants.au3> _ArrayDisplay(_RFC2445Conversion("+P15DT5H0M20S") , "+P15DT5H0M20S") _ArrayDisplay(_RFC2445Conversion("P7W"), "+P7W") _ArrayDisplay(_RFC2445Conversion("-PT1H"), "-PT1H") _ArrayDisplay(_RFC2445Conversion("+P15DT30M"), "+P15DT30M") _ArrayDisplay(_RFC2445Conversion("-15DT30M"), "-15DT30M") _ArrayDisplay(_RFC2445Conversion("+P15DT30"), "+P15DT30") _ArrayDisplay(_RFC2445Conversion("P1D15H"), "P1D15H") _ArrayDisplay(_RFC2445Conversion("P25DT1H2M3S"), "P25DT1H2M3S") Func _RFC2445Conversion($strRawDuration) Local $arrDuration[6], _ $arrPatterns[6] = ["([-+])", _ "(?:(\d+)W)", _ "(?:(\d+)D)", _ "(?:(\d+)H)", _ "(?:(\d+)M)", _ "(?:(\d+)S)"], _ $arrResult If StringRegExp($strRawDuration, "^([-+]?)P(?=\d+[WDHMS])(\d+W)?(\d+D)?(?:T)?(\d+H)?(\d+M)?(\d+S)?$", $STR_REGEXPMATCH) <> 0 Then For $i = 0 To UBound($arrPatterns) - 1 Step 1 $arrResult = StringRegExp($strRawDuration, $arrPatterns[$i], $STR_REGEXPARRAYMATCH) If IsArray($arrResult) Then $arrDuration[$i] = $arrResult[0] Next Else Return SetError(1, 0, 0) EndIf Return $arrDuration EndFunc Edited January 20, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted January 20, 2019 Share Posted January 20, 2019 (edited) So the final version should obviously be #Include <Array.au3> ;$d = "+P15DT5H0M20S" ;$d = "P7W" $d = "+PT1M" ;$d = "+P15DT30M" $res = StringRegExp($d, '(?x)^([-+]?) P(\d+W)?(\d+D)? (?:T(\d+H)?(\d+M)?(\d+S)?)? $', 3) ; maybe some error checking here... Redim $res[6] For $i = 1 to 5 $res[$i] = Number($res[$i]) Next _ArrayDisplay($res) Please note that checking the validity was not initially included in the deal Edited January 20, 2019 by mikell water 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 20, 2019 Share Posted January 20, 2019 (edited) @mikell Only the string P is not a valid input, so, a positive lookahead should do the trick ^([-+]?)P(?=\d+[WDHMS])(\d+W)?(\d+D)?(?:T)?(\d+H)?(\d+M)?(\d+S)?$ @water See this post (edited) Edited January 20, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted January 20, 2019 Author Share Posted January 20, 2019 Thanks guys for your efforts! I'm not going to check the validity of the input file. Translating a valid ics file to Outlook is complex enough. Validating the iCal file is a task for online/offline validators. Example: https://icalendar.org/validator.html So I'm happy with a RegExp that simply splits the property My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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