youtuber Posted February 27, 2020 Share Posted February 27, 2020 I need to get the names Testasdf and Testblabla match https://regex101.com/r/bnsgwG/1 I have done many trials, the regex pattern is very confused and the final pattern is : (?i)^"*.(.*?)|.*(?=.exe)\.\w{2,3}.([^"]+) Link to comment Share on other sites More sharing options...
jchd Posted February 28, 2020 Share Posted February 28, 2020 (edited) What's the condition to not match myprogram as well? If it's for getting program names w/o extension in this sample, use (?i)["\\]([^\\]*)\.exe" Explain your complete requirements in full detail please. Edited February 28, 2020 by jchd youtuber 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) Link to comment Share on other sites More sharing options...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 There I just need the names Testasdf.exe and Testblabla.exe. except program.exe I tried a little closer pattern but I failed https://regex101.com/r/bnsgwG/2 Link to comment Share on other sites More sharing options...
jchd Posted February 28, 2020 Share Posted February 28, 2020 Again, what's the condition to NOT match the other(s) .exe ??? 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...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 (edited) @jchd 1 hour ago, jchd said: (?i)["\\]([^\\]*)\.exe" (?i)["\\]([^ \\]*)\.exe" ; Here is exactly the condition I want when there is one empty, an interesting empty https://regex101.com/r/BL19yc/2 Yes, this works fine for me, thanks, but can it cause problems for a more specific mess? Edited February 28, 2020 by youtuber Link to comment Share on other sites More sharing options...
jchd Posted February 28, 2020 Share Posted February 28, 2020 Please be more specific! Your question is way too vague. 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...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 (edited) I think I should narrow the rules. for example (?i)["\\]([^ \\]*)(?=.exe)\.\w{2,3}" There is a regex pattern that works well for me here. To understand me better. https://regex101.com/r/BL19yc/2 Edited February 28, 2020 by youtuber Link to comment Share on other sites More sharing options...
jchd Posted February 28, 2020 Share Posted February 28, 2020 1 minute ago, youtuber said: (?=.exe)\.\w{2,3} There is redundancy here: you ask for the string .exe to follow the matchpoint and then you want it to match the pattern \.\w{2,3} It's plain that .exe matches \.\w{2,3} 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...
jchd Posted February 28, 2020 Share Posted February 28, 2020 You get the same matches with (?i)["\\]([^ \\]+).exe" youtuber 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) Link to comment Share on other sites More sharing options...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 But if there is no empty, there is no match. In this section ([^\\]+)Thank you. Works well for me (?i)["\\]([^ \\]+).exe" or(?i)["\\]([^ \\]*)\.exe" or(?i)["\\]([^ \\]*)(?=.exe)\.\w{2,3}" Link to comment Share on other sites More sharing options...
jchd Posted February 28, 2020 Share Posted February 28, 2020 Do you encounter empty program names often, like "C:\chkfhi\.exe" ? 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...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 No blank name.no problem. Link to comment Share on other sites More sharing options...
TheXman Posted February 28, 2020 Share Posted February 28, 2020 (edited) "\\?([\w ]+)(?=\.exe) This should also work (with the following assumptions): file name will always be enclosed in double quotes file name will consist of only letters, number, underscores, and spaces file name will always end with .exe file name optionally begins with a "\" directly after the initial double quote I left off the (?i) for case-insensitivity. You can add it back if it's needed. https://regex101.com/r/xYqThi/1 Edited February 28, 2020 by TheXman iamtheky and youtuber 2 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
iamtheky Posted February 28, 2020 Share Posted February 28, 2020 That makes an assumption that the file name is not in a subdirectory as something like this in the last line is not captured ShellExecute(@HomeDrive & "\Program Files\PROGRAMDIR\Program Dir\my program.exe", @ScriptDir & "\test\Testblabla.exe") And the previous lot are equivalent to just acting on an exe with no spaces in the name (?:\\|")\w*.exe i would lean towards the trailing comma as the criteria to exclude "my program.exe" from the example. In both the first Send command and the last Shellexecute, the exe is in the last parameter. youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Malkey Posted February 28, 2020 Share Posted February 28, 2020 Here is a reply to your questions. #include <Array.au3> #cs Send('BLA.CMD "Testasdf.exe" folder\file.txt asdf123') Send('{enter}') ShellExecute(@ScriptDir & "\folder\file.txt") ShellExecute(@HomeDrive & "\Program Files\PROGRAMDIR\Program Dir\my program.exe", @ScriptDir & "\Testblabla.exe") #ce Local $sTestString = StringRegExpReplace(FileRead(@ScriptFullPath), "(?s)^.*?#cs\v+|\v+#ce.*$", "") ; ConsoleWrite($sTestString & @CRLF) $a1 = StringRegExp($sTestString, '(?i)[\w\h]+(?=\.exe"(?:\h|\)))', 3) ; post #1, after results Testasdf and Testblabla _ArrayDisplay($a1) $a2 = StringRegExp($sTestString, '(?i)[\w\h]+\.exe(?="(?:\h|\)))', 3) ; post #3, after results Testasdf.exe and Testblabla.exe _ArrayDisplay($a2) ConsoleWrite(StringRegExpReplace($sTestString, '(?is).*?(?<= "|"\\)([\w\h]+)(\.exe"\h|\.exe"\)).*?', "\1" & ' ') & @CRLF) ; post #1, after results Testasdf and Testblabla ConsoleWrite("------------------" & @CRLF) ConsoleWrite(StringRegExpReplace($sTestString, '(?is).*?(?<= "|"\\)([\w\h]+\.exe)("\h|"\)).*?', "\1" & @CRLF)) ; post #3, after results Testasdf.exe and Testblabla.exe #cs ; Returns @ output console:- Testasdf Testblabla ------------------ Testasdf.exe Testblabla.exe #ce youtuber 1 Link to comment Share on other sites More sharing options...
mikell Posted February 28, 2020 Share Posted February 28, 2020 8 hours ago, iamtheky said: i would lean towards the trailing comma as the criteria to exclude "my program.exe" from the example I agree ... so this should work #Include <Array.au3> $txt = "Send('BLA.CMD ""Testasdf.exe"" folder\file.txt asdf123')" & @crlf & _ "Send('{enter}')" & @crlf & _ "ShellExecute(@ScriptDir & ""\folder\file.txt"")" & @crlf & _ "ShellExecute(@HomeDrive & ""\Program Files\PROGRAMDIR\Program Dir\my program.exe"", @ScriptDir & ""\Testblabla.exe"")" $res = StringRegExp($txt, '(\w+)\.exe(?!.*?,)', 3) _ArrayDisplay($res) iamtheky and youtuber 2 Link to comment Share on other sites More sharing options...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 (edited) @mikell Your sample pattern doesn't work for this #Include <Array.au3> $txt = "Send('BLA.CMD ""Testasdf!^+%&()=_.exe"" folder\file.txt asdf123')" & @crlf & _ "Send('{enter}')" & @crlf & _ "ShellExecute(@ScriptDir & ""\folder\file.txt"")" & @crlf & _ "ShellExecute(@HomeDrive & ""\Program Files\PROGRAMDIR\Program Dir\my program.exe"", @ScriptDir & ""\Testblabla!^+%&()=_.exe"")" $res = StringRegExpReplace($txt, '(\w+)\.exe(?!.*?,)', 'Replacewith.exe') MsgBox(0,"", $res) I will use it for this #include <File.au3> Local $FileSearch = _FileListToArray(@ScriptDir & "\", "*.exe", 1) If Not @error Then For $i = 1 To $FileSearch[0] _ChangeEXEnameINau3($FileSearch[$i]) Next EndIf Func _ChangeEXEnameINau3($aFileNameExe) Local $aFileList = _FileListToArray(@ScriptDir & "\MyprojectAu3\", "*.au3", 1) If Not @error Then For $i = 1 To UBound($aFileList) - 1 $Au3_path = @ScriptDir & "\MyprojectAu3\" & $aFileList[$i] $Read = FileRead($Au3_path) $sRegexRep = StringRegExpReplace($Read, '(\w+)\.exe(?!.*?,)', $aFileNameExe) $Open = FileOpen($Au3_path, 2) FileWrite($Open, $sRegexRep) FileClose($Open) Next EndIf EndFunc ;==>_ChangeEXEnameINau3 Edited February 28, 2020 by youtuber Link to comment Share on other sites More sharing options...
mikell Posted February 28, 2020 Share Posted February 28, 2020 54 minutes ago, youtuber said: Your sample pattern doesn't work for this It's because the file names contain non-word characters. Just replace in the expression \w by [^"] #Include <Array.au3> $txt = "Send('BLA.CMD ""Testasdf!^+%&()=_.exe"" folder\file.txt asdf123')" & @crlf & _ "Send('{enter}')" & @crlf & _ "ShellExecute(@ScriptDir & ""\folder\file.txt"")" & @crlf & _ "ShellExecute(@HomeDrive & ""\Program Files\PROGRAMDIR\Program Dir\my program.exe"", @ScriptDir & ""\Testblabla!^+%&()=_.exe"")" $res = StringRegExpReplace($txt, '([^"]+)\.exe(?!.*?,)', 'Replacewith.exe') MsgBox(0,"", $res) youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted February 28, 2020 Author Share Posted February 28, 2020 @mikell , 1 Does not match when there is a comma at the end of $txt #Include <Array.au3> $txt = "Send('BLA.CMD ""Testasdf!^+%&()=_.exe"" folder\file.txt asdf123', 1)" $res = StringRegExpReplace($txt, '([^"]+)\.exe(?!.*?,)', 'Replacewith.exe') MsgBox(0,"", $res) Link to comment Share on other sites More sharing options...
mikell Posted February 28, 2020 Share Posted February 28, 2020 Hmm. jchd, was right, you must strictly define your requirements Currently it seems that the best way is the concept from Malkey #Include <Array.au3> $txt = "Send('BLA.CMD ""Testasdf!^+%&()=_.exe"" folder\file.txt asdf123', 1)" & @crlf & _ "Send('{enter}')" & @crlf & _ "ShellExecute(@ScriptDir & ""\folder\file.txt"")" & @crlf & _ "ShellExecute(@HomeDrive & ""\Program Files\PROGRAMDIR\Program Dir\my program.exe"", @ScriptDir & ""\Testblabla!^+%&()=_.exe"")" $res = StringRegExpReplace($txt, '[^"]+(?=\.exe"(?:\h|\)))', 'Replacewith.exe') MsgBox(0,"", $res) youtuber 1 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