LoneWolf_2106 Posted June 6, 2018 Share Posted June 6, 2018 (edited) Hi guys, i have a question related to _ArrayFindAll. I have a log file to be analyzed and I have to count how many times a substring in an array occurs. I have created an array which contains all the indexes of the matched strings. $Initial_array contains all the strings(basically my log file). $Laptop_to_be_searched is my substring. $aOccurrences_Laptops=_ArrayFindAll($Initial_array, $Laptop_to_be_searched,0,0,0,1) My problem is that I don't have an exact match. if my substring is "Laptop", it will match all the strings with for example "06.06.2018 LaptopA started" or ""06.06.2018 LaptopB started". What I need is just the exact match, only the entries which contains the substring "Laptop". How can I optimize my search? Thanks in advance, Regards Edited June 6, 2018 by LoneWolf_2106 Link to comment Share on other sites More sharing options...
AutoBert Posted June 6, 2018 Share Posted June 6, 2018 6 minutes ago, LoneWolf_2106 said: How can I optimize my search? Use a regular expression pattern instead of partial search. Param $iCompare Link to comment Share on other sites More sharing options...
LoneWolf_2106 Posted June 6, 2018 Author Share Posted June 6, 2018 how can i pass my variable $Laptop_to_be_searched to the regular expression? can you give me an example, please? something like this: "/INFO\s.\d\d.\d\d.\d\d\d\d\s\d\d.\d\d.\d\d.\s.(http-bio-8080-exec-\d.|http-bio-8080-exec-\d\d).\s."&$Laptop_to_be_searched&"/g" ? Link to comment Share on other sites More sharing options...
Subz Posted June 6, 2018 Share Posted June 6, 2018 I'm not that great at Regex but this should work: #include <Array.au3> Local $aLaptopLog[6] = ["06.06.2018 LaptopA started", "06.06.2018 Laptop started", "06.06.2018 LaptopA started", "06.06.2018 LaptopB started", "06.06.2018 LaptopA started", "06.06.2018 Laptop started"] Local $sLaptop_to_be_searched = "Laptop" Local $aOccurrences_Laptops = _ArrayFindAll($aLaptopLog, "(?<![\w\d])" & $sLaptop_to_be_searched & "(?![\w\d])", 0, 0, 0, 3) _ArrayDisplay($aOccurrences_Laptops) LoneWolf_2106 1 Link to comment Share on other sites More sharing options...
LoneWolf_2106 Posted June 6, 2018 Author Share Posted June 6, 2018 @Subz thank you so much 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