Jump to content

Help with StringRegExp!


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...