Jump to content
Sign in to follow this  
logmein

Help with StringRegExp!

Recommended Posts

logmein

How can I use StringRegExp to detect this format of string: [Drive]\[Folder1]\[Folder2]\[...]\[Filename][.ext1][.ext2(exe, bat)]

Sample paths :

C:\British\SpitFire.html.exe
C:\Luftwaffe\Stuka.txt.exe
D:\Soviet\Sturmovik.doc.bat
D:\USA\American\HawkerHurricane.backup.exe

Thanks alot! :idea:

Edited by logmein

Share this post


Link to post
Share on other sites
JRowe

your regular expression would be something like this:

"(\w\:\\)(\w*\\+)*(\w+\.+\w+)*"

First group is the drive, second group is the path, third group is the filename.

You'll have to parse the path using stringexplode on the backslash "\" if you want to further break it down.

Edited by JRowe

Share this post


Link to post
Share on other sites
PsaltyDS

Cause I'm tired and have to stay awake:

#include <Array.au3> ; Only for _ArrayDisplay()

Global $aStrings[4] = ["C:\British\SpitFire.html.exe", _
    "C:\Luftwaffe\Stuka.txt.exe", _
    "D:\Soviet\Sturmovik.doc.bat", _
    "D:\USA\American\HawkerHurricane.backup.exe"]

Global $sPatt = "(?i)([[:alpha:]]:)(?:\\)(.+)(?:\\)(.+\.(?:exe|bat)\Z)", $aRET

For $n = 0 To UBound($aStrings) - 1
    $aRET = StringRegExp($aStrings[$n], $sPatt, 3)
    If IsArray($aRET) Then
        _ArrayDisplay($aRET, $n & ": $aRET")
    Else
        ConsoleWrite($n & ": Failed: @error = " & @error & "; @extended = " & @extended & @LF)
    EndIf
Next

:idea:

Edit: Forgot the alternative (exe|bat)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.