rootx Posted April 28, 2015 Posted April 28, 2015 $text = 'C:\xxx\hh\hhhh\hhh\image.JPG' $out = StringRegExp($text,'.*\\(.*)\\',1)Return the last folder hhh.I would use this expression in the cycle below. Local $aArray = _FileListToArrayRec("C:\test\app", "*app.exe", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH) $fileArray = UBound($aArray) -1 For $y = 1 To $fileArray _GUICtrlListView_AddItem($ListView, StringRegExp($aArray[$y],'.*\\(.*)\\',1), 0) Next My target is to remove everything from the path, and take only the last folder.Thanks
jchd Posted April 28, 2015 Posted April 28, 2015 Local $aArray = _FileListToArrayRec("C:\test\app", "*app.exe", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH) $fileArray = UBound($aArray) -1 For $y = 1 To $fileArray _GUICtrlListView_AddItem($ListView, StringRegExp($aArray[$y],'.*\\(.*)\\',1)[0], 0) NextShould work with recent version (untested). rootx 1 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 hereRegExp tutorial: enough to get startedPCRE 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)
mikell Posted April 28, 2015 Posted April 28, 2015 StringRegExp returns an array and your code needs a string then you also could use StringRegExpReplace$text = 'C:\xxx\hh\hhhh\hhh\image.JPG' $out = StringRegExpReplace($text, '.*\\(.*)\\.*', "$1") msgbox(0,"", $out) rootx 1
rootx Posted April 29, 2015 Author Posted April 29, 2015 Thanks guys, perfect. One more question, between the two methods which one is more powerful?
mikell Posted April 29, 2015 Posted April 29, 2015 (edited) I don't understand 'powerful'Meaning speed, the SRER may be a little slower because of the backreferencing but the difference is anecdotic if the expression is built for this purpose (the SRE could also be modified though) $text = 'C:\xxx\hh\hhhh\hhh\image.JPG' $t1 = TimerInit() For $i = 1 to 10000 $out = StringRegExpReplace($text, '.*\\([^\\]+)\\[^\\]*', "$1") Next $r1 = TimerDiff($t1) Sleep(100) $t2 = TimerInit() For $i = 1 to 10000 $out = StringRegExp($text, '.*\\(.*)\\', 1)[0] Next $r2 = TimerDiff($t2) Msgbox(0,"", "$out1 = " & $r1 & @crlf & "$out2 = " & $r2) Edited April 29, 2015 by mikell
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now