Jump to content
LoneWolf_2106

_ArrayFindAll exact match

Recommended Posts

LoneWolf_2106
Posted (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 by LoneWolf_2106

Share this post


Link to post
Share on other sites
AutoBert
6 minutes ago, LoneWolf_2106 said:

How can I optimize my search?

Use a regular expression pattern instead of partial search. Param $iCompare

 

Share this post


Link to post
Share on other sites
LoneWolf_2106

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"

?

Share this post


Link to post
Share on other sites
Subz

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)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
LoneWolf_2106

@Subz thank you so much

Share this post


Link to post
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

×