Jump to content

_ArrayFindAll exact match


Recommended Posts

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 by LoneWolf_2106
Link to comment
Share on other sites

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

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)

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...