> On Dec 18, 2024, at 15:56, AP <gnuc...@inml.grue.cc> wrote: > > On Tue, Dec 17, 2024 at 08:01:01PM -0800, John Ralls wrote: >> I’d made an error when I wrote bit in the bundler script that derives the >> version to pass to the setup-generator: It gets the release instal >> directories, sorts them, and grabs the last one. The problem with that is >> that it’s a lexical sort so if say 5.8, 5.9. and 5.10 directories exist then >> the sort order is >> Gnucash-5.10 >> Gnucash-5.8 >> Gnucash-5.9 >> And the last one is 5.9. >> https://github.com/Gnucash/gnucash-on-windows/commit/317b10b7d99a4ae8281e866efc4403b9b7624320 >> changes it to sort them by creation date. That’s still not perfect, of >> course, because someone might come along and builds an earlier version by >> hand it will have the last time stamp. > > I asked the Lord God AI (as I'm not a powershell user) and it came up with > this: > > --- 8<--- > # Define an array of strings with non-version related text before the version > numbers > $versionStrings = @( > 'ProductA v1.2.3', > 'ProductB v1.10.0', > 'ProductC v1.3.5', > 'ProductD v2.0.0' > ) > > # Extract the version part using a regular expression and sort by the > extracted version > $sortedVersions = $versionStrings | Sort-Object { > if ($_ -match 'v([\d\.]+)$') { > [version]$matches[1] > } > } > > # Display the sorted versions > $sortedVersions > --- 8<--- > > Don't know how right it is but if it's not right in and of itself then, > maybe, it's right enough to get you most of the way there. :) >
You don’t show the output, but the result of the regex match is still a string so I think it will still sort lexically, i.e. 1.10.0, 1.2.3, 1.3.5, 2.0.0. This S-O suggests using a function called System.Version: https://stackoverflow.com/questions/711107/sorting-powershell-versions. Dunno if it works on two-digit version numbers. My default approach in most languages would be to do two captures, ‘(\d+).(\d+)$’ and cast each to int and do a two-level sort. https://stackoverflow.com/questions/71232189/how-to-sort-multilevel-list suggests how to do the multi-level sort part. Regards, John Ralls _______________________________________________ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user ----- Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.