ARTIFACTORY: How to retrieve all artifacts in a repo except the latest 2 versions

ARTIFACTORY: How to retrieve all artifacts in a repo except the latest 2 versions

AuthorFullName__c
Sara Ngo
articleNumber
000005700
ft:sourceType
Salesforce
FirstPublishedDate
2023-04-30T11:53:26Z
lastModifiedDate
2023-04-30
VersionNumber
1

This article will provide a solution for searching all artifacts in a repo except the latest 2 versions based on their names, irrespective of created date and download history. For example, using this method, I can retrieve the RPM packages 

rpm-4.18.1-3-omv2390.x86_64.rpm
rpm-4.18.2-3-omv2390.x86_64.rpm
rpm-4.18.3-3-omv2390.x86_64.rpm
which are older versions.
User-added image

This solution can be applied to maven, npm, nuget, debian, rpm, python, gems.