InclusiveExclusion Posted January 22, 2021 Share Posted January 22, 2021 Hi Guys, I'm reading in a file and looking to get first the version number of ProgramA then the version number of ProgramB. The file looks like this inside: ProgramA.exe Directory: C:\Program Files\Maker\ProgramAFolder Product Version: 1.0.455.0 File Version: 1.0.455.0 Creation Date: 05/15/2019 19:02:00 ProgramB.exe Directory: C:\Program Files\Maker\ProgramBFolder Product Version: 1.0.456.0 File Version: 1.0.456.0 Creation Date: 05/15/2019 19:04:00 I can do this and just get both product numbers at once but I'm trying to just make an expression to get one, then another expression to get the other. This gets both at once successfully: svc = StringRegExp($contents,"Product\hVersion:\h(\d+\.\d+\.\d+.\d+)",3) I tried to do it to just get Program A Product Version and that's where I fell off the edge of the map. Below is what I did. Its a real mess. $svc = StringRegExp($contents,"(?m)ProgramA\.exe$.+$.+Product\hVersion:\h(\d+\.\d+\.\d+.\d+)) Would someone please help me to get this multi line regex working? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 22, 2021 Share Posted January 22, 2021 @InclusiveExclusion Maybe something like this: #include <StringConstants.au3> Test() Func Test() Local $strTestString = "ProgramA.exe" & @CRLF & _ "Directory: C:\Program Files\Maker\ProgramAFolder" & @CRLF & _ "Product Version: 1.0.455.0" & @CRLF & _ "File Version: 1.0.455.0" & @CRLF & _ "Creation Date: 05/15/2019 19:02:00" & @CRLF & @CRLF & _ "ProgramB.exe" & @CRLF & _ "Directory: C:\Program Files\Maker\ProgramBFolder" & @CRLF & _ "Product Version: 1.0.456.0" & @CRLF & _ "File Version: 1.0.456.0" & @CRLF & _ "Creation Date: 05/15/2019 19:04:00", _ $strPattern = "(?s)(\w+\.exe).*?Product Version:\h*(\N+)", _ $arrResult, _ $arrFileVersions[1][2] = [["Filename", "Version"]] $arrResult = StringRegExp($strTestString, $strPattern, $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then _ArrayDisplay($arrResult) For $i = 0 To UBound($arrResult) - 1 Step 2 _ArrayAdd($arrFileVersions, $arrResult[$i] & "|" & $arrResult[$i + 1]) Next _ArrayDisplay($arrFileVersions) EndFunc 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...
Musashi Posted January 22, 2021 Share Posted January 22, 2021 Or maybe : #include <Array.au3> Local $sText = " ProgramA.exe" & @CRLF & _ " Directory: C:\Program Files\Maker\ProgramAFolder" & @CRLF & _ " Product Version: 1.0.455.0" & @CRLF & _ " File Version: 1.0.455.0" & @CRLF & _ " Creation Date: 05/15/2019 19:02:00" & @CRLF & _ " " & @CRLF & _ " ProgramB.exe" & @CRLF & _ " Directory: C:\Program Files\Maker\ProgramBFolder" & @CRLF & _ " Product Version: 1.0.456.0" & @CRLF & _ " File Version: 1.0.456.0" & @CRLF & _ " Creation Date: 05/15/2019 19:04:00 " $aSvc = StringRegExp($sText,"(?i)(?s)ProgramA\.exe.*?Product Version:.*?(\d+\.\d+\.\d+.\d+)", 3) _ArrayDisplay($aSvc) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
mikell Posted January 22, 2021 Share Posted January 22, 2021 For the fun #Include <Array.au3> $txt = "ProgramA.exe" & @crlf & _ " Directory: C:\Program Files\Maker\ProgramAFolder" & @crlf & _ " Product Version: 1.0.455.0" & @crlf & _ " File Version: 1.0.455.0" & @crlf & _ " Creation Date: 05/15/2019 19:02:00" & @crlf & _ " " & @crlf & _ "ProgramB.exe" & @crlf & _ " Directory: C:\Program Files\Maker\ProgramBFolder" & @crlf & _ " Product Version: 1.0.456.0" & @crlf & _ " File Version: 1.0.456.0" & @crlf & _ " Creation Date: 05/15/2019 19:04:00" $r = Execute("'" & StringRegExpReplace($txt, "(?ms)^(\w+).*?Product Version: (\S+)\R(\h\N+\R?)+", "' & '$1|$2' & '") & "'") Local $a[0][2] _ArrayAdd($a, $r) _ArrayDisplay($a) FrancescoDiMuro 1 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