youtuber Posted June 11, 2019 Share Posted June 11, 2019 (edited) I want to get the file name that says _stripped.au3 at the end of the file I can't get the file name. testV5.1_autoit_stripped.au3 testau3_test.au3 dadasdasd.au3 autoit_autoit.au3 test_stripped.txt #include <File.au3> $path = @ScriptDir $filter = "*.au3" $search = _FileListToArray($path, $filter) If IsArray($search) Then For $i = 1 To $search[0] $RegExp = StringRegExp($search[$i], '(?i)([^_]+)_stripped.au3', 3) If IsArray($RegExp) Then ConsoleWrite($RegExp[0] & @CRLF) EndIf Next EndIf Edited June 11, 2019 by youtuber Link to comment Share on other sites More sharing options...
iamtheky Posted June 11, 2019 Share Posted June 11, 2019 (edited) can you just put it in the filter? #include <File.au3> #include<Array.au3> $path = @ScriptDir $filter = "*_stripped.au3" $search = _FileListToArray($path, $filter) _ArrayDisplay($search) Edited June 11, 2019 by iamtheky youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted June 11, 2019 Share Posted June 11, 2019 $RegExp = StringRegExp($search[$i], '(?i)(.+)_stripped.au3', 3) youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 11, 2019 Author Share Posted June 11, 2019 @mikell All name samplename_stripped.au3 I guess this should be but I'm not sure I would have any problems : (?i).*_stripped.au3 @iamtheky works yes but i wonder with regex thanks :) Link to comment Share on other sites More sharing options...
iamtheky Posted June 11, 2019 Share Posted June 11, 2019 $path = @ScriptDir $filter = "*_stripped.au3" $search = _FileListToArrayRec($path, $filter) now it uses regex youtuber and FrancescoDiMuro 1 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted June 11, 2019 Share Posted June 11, 2019 @youtuber I used .+ because I assumed that you have no file with the name "_stripped.au3" , but you can use .* as well If you remove parenthesis then you don't remove "_stripped.au3" from the filename 8 hours ago, iamtheky said: now it uses regex Yes but it again doesn't allow to remove the filter from the filename. Let's say that using this option or not is left to the OPs choice youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 15, 2019 Author Share Posted June 15, 2019 @iamtheky @mikell If the file name was this, stripped_v3.au3,stripped_v4.au3,stripped_v5.au3,stripped_v5.1.au3,stripped_v5.2.au3 do you think the following filtering is correct? $filter = "stripped_v*.au3" $search = _FileListToArrayRec($path, $filter) or $filter = "stripped_v?.au3" $search = _FileListToArrayRec($path, $filter) otherwise, would it be more accurate to use regex? $RegExp = StringRegExp($search[$i], 'stripped_v(\d(.*?){1,2}).au3', 3) Link to comment Share on other sites More sharing options...
iamtheky Posted June 15, 2019 Share Posted June 15, 2019 (edited) they are all regex, and either can be built to accomodate large buckets of edge cases. I dont know that there is anywhere to find a preference that isnt pedantic af. Edited June 15, 2019 by iamtheky FrancescoDiMuro 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2019 Share Posted June 15, 2019 (edited) except that this (.*?){1,2} is somewhat inconsistent ( 0 or more chars, lazy, 1 or 2 times ?!? ) Hint : if the translation of the regex in "usual" language makes no sense, this probably means that the regex makes no sense too Edited June 15, 2019 by mikell iamtheky, youtuber and FrancescoDiMuro 2 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 15, 2019 Author Share Posted June 15, 2019 (edited) Here is a consistent pattern Global $Fileversion[6] = ["asdasfasfasd", _ "stripped_v0.au3", _ "stripped_v3.au3", _ "stripped_v4.au3", _ "stripped_v5.au3", _ "stripped_v5.1.0.0.au3"] For $i = 0 To 5 $RegExp = StringRegExp($Fileversion[$i], 'stripped_v[\d\.]{0,9}.au3', 3) If IsArray($RegExp) Then ConsoleWrite($RegExp[0] & @CRLF) EndIf Next Edited June 15, 2019 by youtuber Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 15, 2019 Share Posted June 15, 2019 @youtuber You shouldn't even escape the dot in the character class, since it's automatically taken as literal character; you should instead escape the one outside the character class, before the file extension: stripped_v[\d.]\.au3 stripped_v[0-9.]\.au3 youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2019 Share Posted June 15, 2019 38 minutes ago, youtuber said: Here is a consistent pattern Consistent ? yes. Efficient ? no. Just test it on this Global $Fileversion[6] = ["asdasfasfasd", _ "stripped_v5.au3", _ "stripped_v......au3", _ "stripped_v.....5.au3", _ "stripped_v15.12.10.10.au3", _ "stripped_v5....au3"] Here is the clean way $RegExp = StringRegExp($Fileversion[$i], 'stripped_v\d+(?:\.\d+)*\.au3', 3) youtuber 1 Link to comment Share on other sites More sharing options...
Nine Posted June 15, 2019 Share Posted June 15, 2019 19 minutes ago, mikell said: StringRegExp($Fileversion[$i], 'stripped_v\d+(?:\.\d+)*\.au3', 3) That wouldn't work with "stripped_v5.au3.txt". But this simple "^stripped_v.+\.au3$" is working, no ? youtuber 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2019 Share Posted June 15, 2019 18 minutes ago, Nine said: That wouldn't work with "stripped_v5.au3.txt". Right. It should be : 'stripped_v\d+(?:\.\d+)*\.au3$' ( trailing $ added) You perfectly showed that regex is not as simple as it seems 18 minutes ago, Nine said: this simple "^stripped_v.+\.au3$" is working, no ? this one matches "stripped_vademecum#;;lol-.au3" .... youtuber 1 Link to comment Share on other sites More sharing options...
Nine Posted June 15, 2019 Share Posted June 15, 2019 2 minutes ago, mikell said: this one matches "stripped_vademecum#;;lol-.au3" .... Ok, I got it. You want to have a pattern after _v of digits/dot/digits/dot...Nothing else. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2019 Share Posted June 15, 2019 Yes. It was not explicit in the OPs requirements but I assumed that what was to be matched was a version number with a correct syntax youtuber 1 Link to comment Share on other sites More sharing options...
Nine Posted June 15, 2019 Share Posted June 15, 2019 3 minutes ago, mikell said: Yes. It was not explicit in the OPs requirements but I assumed that what was to be matched was a version number with a correct syntax Alright, make sense. But then you still need to add ^ at the beginning otherwise you would get false positive with "#123;456:.stripped_v5.au3" “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2019 Share Posted June 15, 2019 Right again I was still remembering the first posts of this thread and I focused on the " stripped_v" + version number Link to comment Share on other sites More sharing options...
moosjuice Posted June 15, 2019 Share Posted June 15, 2019 (edited) I'm sorry to plug my program here but I must, for there is something this hobbyist may have gleamed from its vast reserves if he had known in advance, and therefore not ask this question. Which wastes all our time! That's important! If you look at what I did there, $aRegExSFile, it perfectly matches this situation. (((.*)(?=\\)\N)|(\\))(.*?)\z The only difference is change \z to $, add stripped_v and .au3, and put the .*? in between them. (((.*)(?=\\)\N)|(\\))(stripped_v)(.*?)(.au3)$ https://www.debuggex.com/r/AwbaT9ONYtDiqO7W Edited June 15, 2019 by moosjuice youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 15, 2019 Author Share Posted June 15, 2019 regex like love 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