Spider001 Posted December 8, 2014 Share Posted December 8, 2014 $filename = 'test.txt.exe.bat' $filename = StringReverse ($filename) $filename = StringRight($filename,StringLen($filename) - StringInStr($filename,'.')) $filename = StringReverse ($filename) ConsoleWrite($filename) ConsoleWrite(@CRLF) Can you do this with StringRegExpReplace or StringRegExp. remove only the file extension. Link to comment Share on other sites More sharing options...
Solution mikell Posted December 8, 2014 Solution Share Posted December 8, 2014 (edited) $filename = StringRegExpReplace($filename, '(.*)\..*', "$1") $filename = StringRegExpReplace($filename, '\.[^.]*?$', "") etc Edited December 8, 2014 by mikell Link to comment Share on other sites More sharing options...
Spider001 Posted December 8, 2014 Author Share Posted December 8, 2014 (edited) Thank you this works fantastic. how do you let StringRegExpReplace nows its the last . he need ? think i found it the $ sign to start at the end ? Edited December 8, 2014 by Spider001 Link to comment Share on other sites More sharing options...
mikell Posted December 8, 2014 Share Posted December 8, 2014 (edited) In the first expression, (.*) is greedy so the regex will grab in the backreference all chars until the last dot found In the 2nd, read : "a dot, and 0 or more non-dot chars (lazy), up to the end" This laziness means that the concerned dot must be the last one found before the end Edited December 8, 2014 by mikell Link to comment Share on other sites More sharing options...
Spider001 Posted December 8, 2014 Author Share Posted December 8, 2014 Your example is used at a real script. thanks for the explanation i want to learn this. this is a function i have always problems with Link to comment Share on other sites More sharing options...
Exit Posted December 8, 2014 Share Posted December 8, 2014 (edited) this is a function i have always problems with Don't worry, you are not the only one. I'll join the queue.Your original solution is slower than the regex solutions. But my solution without regex is the fastest. Here the script:$sFilename = 'test.txt.exe.bat' $iLoopcount = 200000 $iTimer = TimerInit() For $i = 1 To $iLoopcount $sNewFilename = StringReverse($sFilename) $sNewFilename = StringRight($sNewFilename, StringLen($sNewFilename) - StringInStr($sNewFilename, '.')) $sNewFilename = StringReverse($sNewFilename) Next $iTime = TimerDiff($iTimer) ConsoleWrite("Using StringReverse" & @CRLF) ConsoleWrite($sNewFilename & " " & $iTime & @CRLF & @CRLF) $iTimer = TimerInit() For $i = 1 To $iLoopcount $sNewFilename = StringRegExpReplace($sFilename, '(.*)\..*', "$1") Next $iTime = TimerDiff($iTimer) ConsoleWrite("Using StringRegExpReplace Pattern 1" & @CRLF) ConsoleWrite($sNewFilename & " " & $iTime & @CRLF & @CRLF) $iTimer = TimerInit() For $i = 1 To $iLoopcount $sNewFilename = StringRegExpReplace($sFilename, '\.[^.]*?$', "") Next $iTime = TimerDiff($iTimer) ConsoleWrite("Using StringRegExpReplace Pattern 2" & @CRLF) ConsoleWrite($sNewFilename & " " & $iTime & @CRLF & @CRLF) $iTimer = TimerInit() For $i = 1 To $iLoopcount $sNewFilename = StringLeft($sFilename, StringInStr($sFilename, ".", 0, -1) - 1) Next $iTime = TimerDiff($iTimer) ConsoleWrite("Using StringLeft" & @CRLF) ConsoleWrite($sNewFilename & " " & $iTime & @CRLF & @CRLF)And here the result:Using StringReverse test.txt.exe 7111.68181138629 Using StringRegExpReplace Pattern 1 test.txt.exe 1545.96028171841 Using StringRegExpReplace Pattern 2 test.txt.exe 1211.85814138758 Using StringLeft test.txt.exe 1022.85245008591Conclusion:Regex is not always the best solution. Edited December 9, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
guinness Posted December 9, 2014 Share Posted December 9, 2014 In the latest beta it should be. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2014 Share Posted December 9, 2014 >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:UsersADMIN010Documentsaa.au3" /UserParams +>04:35:09 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0 Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) +> SciTEDir => C:Program Files (x86)AutoIt3SciTE UserDir => C:UsersADMIN010AppDataLocalAutoIt v3SciTEAutoIt3Wrapper SCITE_USERHOME => C:UsersADMIN010AppDataLocalAutoIt v3SciTE >Running AU3Check (3.3.13.19) from:C:Program Files (x86)AutoIt3Beta input:C:UsersADMIN010Documentsaa.au3 +>04:35:09 AU3Check ended.rc:0 >Running:(3.3.13.19):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:UsersADMIN010Documentsaa.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Using StringReverse test.txt.exe 5916.72078644539 Using StringRegExpReplace Pattern 1 test.txt.exe 987.68195765385 Using StringRegExpReplace Pattern 2 test.txt.exe 880.383014436886 Using StringLeft test.txt.exe 924.562870379159 +>04:35:18 AutoIt3.exe ended.rc:0 +>04:35:18 AutoIt3Wrapper Finished. >Exit code: 0 Time: 9.334 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Malkey Posted December 9, 2014 Share Posted December 9, 2014 Getting rid of the unnecessary lazy qualifier in '.[^.]*?$', and adding a possessive qualifier to stop any unnecessary backtracking,we have:- $filename = StringRegExpReplace($filename, '\.[^.]++$', "") Or, '.[^.]*+$' also works. When running:AutoIt Beta version 3.3.13.19, this StringRegExpReplace pattern is the fastest when added to Exit's example of post #6 and run on my (OS:WIN_7/Service Pack 1 CPU:X64 OS:X64) system. Link to comment Share on other sites More sharing options...
jchd Posted December 9, 2014 Share Posted December 9, 2014 Right. Both possessive qualifier and atomic groups deserve a more common use. 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) Link to comment Share on other sites More sharing options...
Exit Posted December 9, 2014 Share Posted December 9, 2014 (edited) In the latest beta it should be. Yes, in the latest beta, the REGEX with pattern2 had the better value. Now, I tweaked my solution to be case insensitive ...., and this solution made the race. Script: expandcollapse popup$sF = 'test.txt.exe.bat' $iLc = 200000 ConsoleWrite("AutoIt Version: " & @AutoItVersion & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringReverse($sF) $sN = StringRight($sN, StringLen($sN) - StringInStr($sN, '.')) $sN = StringReverse($sN) Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringReverse" & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringRegExpReplace($sF, '(.*)\..*', "$1") Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringRegExpReplace Pattern 1" & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringRegExpReplace($sF, '\.[^.]*?$', "") Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringRegExpReplace Pattern 2" & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringRegExpReplace($sF, '\.[^.]++$', "") Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringRegExpReplace Pattern 3" & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringLeft($sF, StringInStr($sF, ".", 0, -1) - 1) Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringLeft" & @CRLF) $iTime = TimerInit() For $i = 1 To $iLc $sN = StringLeft($sF, StringInStr($sF, ".", 1, -1) - 1) Next $iTime = TimerDiff($iTime) ConsoleWrite($sN & " " & $iTime & " Using StringInString casesensitive " & @CRLF) Output: AutoIt Version: 3.3.12.0 test.txt.exe 7500.66292707802 Using StringReverse test.txt.exe 1646.92385042465 Using StringRegExpReplace Pattern 1 test.txt.exe 1288.35341365462 Using StringRegExpReplace Pattern 2 test.txt.exe 1253.17301843785 Using StringRegExpReplace Pattern 3 test.txt.exe 1039.94437720284 Using StringLeft test.txt.exe 907.057500783347 Using StringInString casesensitive AutoIt Version: 3.3.13.19 test.txt.exe 6964.1790005509 Using StringReverse test.txt.exe 1128.0553115061 Using StringRegExpReplace Pattern 1 test.txt.exe 1011.7741747203 Using StringRegExpReplace Pattern 2 test.txt.exe 932.270028610106 Using StringRegExpReplace Pattern 3 test.txt.exe 1066.81534910678 Using StringLeft test.txt.exe 921.09672755274 Using StringInString casesensitive But I'm sure, a REGEX guru will show a even faster solution. > Edited December 9, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Exit Posted December 9, 2014 Share Posted December 9, 2014 When running:AutoIt Beta version 3.3.13.19, this StringRegExpReplace pattern is the fastest when added to Exit's example of post #6 and run on my (OS:WIN_7/Service Pack 1 CPU:X64 OS:X64) system. I incorporated your new solution in my post #11 Again, REGEX is not the fastest. But the race not finished. Awaiting new pattern. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
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