Jump to content

Regex Testing For Highest Version Number in Dir Listing


Recommended Posts

Hey guys,

I'm getting a directory listing of folders within a folder on the network with _FileListToArray then I need to search through that list and determine which folder is named with the largest version number. 

The problem I'm having is with weeding out folders that are not named in the version numbering naming convention.   That naming convention is:   must only contain numbers and full stops like 1.2.3 or 2.8.14 and there can be two or more sets of numbers  eg 1.2  or 1.2.3 or 1.2.3.4 etc.  

Would someone please tip me off on whats wrong with my regex?

#include <array.au3>

Local $array = ["1.7.8","1.7.9","1Goat.Eating.Pastrami.2.3","128","1.7.10","TriggeredLefty.69"]

for $x = 0 to Ubound($array)-1
    if StringRegExp($array[$x],"[\d\.^\w]+") = 1 Then   ;<<<<< y u no work!!!
        $aThisEl = StringSplit($array[$x],".",2)
        _ArrayDisplay($aThisEl,"This version")
    EndIf
Next

 

Link to comment
Share on other sites

#include <array.au3>

Local $array = ["1.7.8","1.7.9","1Goat.Eating.Pastrami.2.3","128","1.7.10","TriggeredLefty.69"]

for $i = 0 to ubound($array) - 1
    stringregexpreplace($array[$i] , "(.*[A-Za-z].*)" , "")
    If @extended = 0 then  _ArrayDisplay(stringsplit($array[$i] , "." , 2))
next

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Like this?

Local $array = ["1.7.8","1.7.9","1Goat.Eating.Pastrami.2.3","128","1.7.10","TriggeredLefty.69", "14.23.8.is that correct?", "And that:2.3.4 something"]
Local $aRes
For $x = 0 to Ubound($array) - 1
    $aRes = StringRegExp($array[$x],"^\d+(?:\.\d+)+$", 3)
    If Not @error Then
        ConsoleWrite("Version found: " & $aRes[0] & " in " & $array[$x] & @LF)
    EndIf
Next

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi.

Others reading this thread might not be familiar with _versioncompare() ... ;)

 

#include <Misc.au3>

Local $array = ["1.7.8", "1.7.9", "1Goat.Eating.Pastrami.2.3", "128", "1.7.10", "TriggeredLefty.69", "14.23.8.is that correct?", "And that:2.3.4 something"]
Local $aRes
Local $MaxVer = False
For $x = 0 To UBound($array) - 1
    $aRes = StringRegExp($array[$x], "^\d+(?:\.\d+)+$", 3)
    If Not @error Then
        ConsoleWrite("Version found: " & $aRes[0] & " in " & $array[$x] & @LF)
        If $MaxVer Then
            If _VersionCompare($aRes[0], $MaxVer) = 1 Then
                $MaxVer = $aRes[0]
                ConsoleWrite("Higher version found: " & $MaxVer & @CRLF)
            EndIf
        Else
            $MaxVer = $aRes[0]
            ConsoleWrite("First Version found: " & $MaxVer & @CRLF)
        EndIf
    EndIf
Next

ConsoleWrite("------------------------------------------" & @CRLF)

if $MaxVer Then
    ConsoleWrite("higest version found: " & $MaxVer & @CRLF)
Else
    ConsoleWrite("no version found at all!" & @CRLF)
EndIf

regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...