StringRegExp Kudelmuddel

  • Moin,

    ich weiss, das Thema wurde schon oft abgehandelt, aber leider habe ich mit der Suchfunktion auch keine Lösung gefunden...

    Ich habe Probleme mit dem definieren von Gruppen, Sets usw.

    Also, wie schon hier einmal besprochen wurde, möchte ich von einem Pfad nur den Dateinamen ohne Endung herausfiltern.
    Ich weiss, das geht auch mit StringSplit, aber ich denke es müsste auch mit RegExp gehen, oder ?

    Ich bin jetzt so vorgegangen...

    $FileName = StringRegExp(SourceTracks[1], '\\.*\.', 1)

    Nun bekomme ich aber den String vom ersten Backslash bis zum Punkt zurück !

    Wie kann ich das nun auf den Daeinamen eingrenzen ?


    Gruß
    Greenhorn


    • Offizieller Beitrag

    Hallo,

    so was?

    [autoit]

    $Filename = StringRegExp("c:\Sub1\Sub2\Sub3\Name.tst",".*\\(.*)",1) ; Dateiname mit Erweiterung
    MsgBox(0,"",$Filename[0])

    [/autoit][autoit][/autoit][autoit]

    $Filename = StringRegExp("c:\Sub1\Sub2\Sub3\Name.tst",".*\\(.*)\..*",1) ; Dateiname ohne Erweiterung
    MsgBox(0,"",$Filename[0])

    [/autoit]
    • Offizieller Beitrag

    Hi,

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ; Function Name: _PathSplit1()
    ; Description: Split the path to 8 elements.
    ; Parameter(s): $sPath - Path to split.
    ; Requirement(s): AutoIt 3.2.2.0.
    ; Return Value(s): On seccess - Array $RetArray that contain 8 elements:
    ; $RetArray[0] = Full path ($sPath)
    ; $RetArray[1] = Drive letter
    ; $RetArray[2] = Path without FileName and extension
    ; $RetArray[3] = Full path without File Extension
    ; $RetArray[4] = Full path without drive letter
    ; $RetArray[5] = FileName and extension
    ; $RetArray[6] = Just Filename
    ; $RetArray[7] = Just Extension of a file
    ;
    ; On failure - If $sPath not include correct path (the path is not splitable),
    ; then $sPath returned.
    ; If $sPath not include needed delimiters, or it's emty,
    ; then @error set to 1, and returned -1.
    ;
    ; Note(s): The path can include backslash as well (exmp: C:/test/test.zip).
    ;
    ; Author(s): G.Sandler a.k.a CreatoR (MsCreatoR) - Thanks to amel27 for help with RegExp
    ;===============================================================================
    Global $text = ''
    $a = _PathSplit1(@ScriptFullPath)
    For $i = 0 To UBound($a) - 1
    $text &= $a[$i] & @CRLF
    Next
    MsgBox(0, "", $text)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _PathSplit1($sPath)
    If $sPath = "" Or StringRegExp($sPath, ('.*\\.*\/')) Then Return SetError(1, 0, -1)
    Local $RetArray[8], $pDelim = ""
    If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
    If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"
    If $pDelim = "" Then $pDelim = "/"
    If Not StringInStr($sPath, $pDelim) Then Return $sPath
    If $pDelim = "\" Then $pDelim &= "\"
    $RetArray[0] = $sPath
    $RetArray[1] = StringRegExpReplace($sPath, $pDelim & '.*', $pDelim)
    $RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '')
    $RetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '')
    $RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & ')', '')
    $RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '')
    $RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]*$', '')
    $RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '')
    Return $RetArray
    EndFunc ;==>_PathSplit1

    [/autoit]

    So long,

    Mega

  • Ihr macht mein Herz mal wieder freudig ! :D

    Vielen Dank an euch ! :kiss:

    Aber trotzdem ist die RegExp-Geschichte ziemlich undurchsichtig für mich... :weinen:
    Muss mich hier wohl eingehend mit beschäftigen...


    Gruß
    Greenhorn