To count the number of exact match of a keyword from a string

Hi

I have to count the no of (0% loss) with brackets from a string. I got the solution by using Regex and match count. I am using below expressions:
System.Text.RegularExpressions.Regex.Matches(str_out1,“(0% loss)”).count - It is giving the right count that is ok. But when I am testing by changing “(20% loss)” in the string.It is also giving the same count.
I want to find the exact match count for “(0% loss)”. Someone please help me in this to form correct regular expression for exact match.

Thanks,
Alamgir

Can you share the string

Hy, You can use the ‘Matches’ Activity like this:

image

The Result is a variable with all the matches, you can get the conter like this:

image

and this is the final result:

image

Regards

Hi @ImPratham45

Sure, String.txt (3.1 KB)

This is a sample text.

Hey @William_Blech_Sister

I am getting count as 0 for “(0% loss)” . Could you please help me with expression for this keyword.

Used this expression:
image

You can also try using this

Split(txt,“(0% loss)”).Length-1

2 Likes

Thanks @ImPratham45

Its working fine.

Great!

Please mark it as solution to close the topic :+1:

Happy Automation!

Hi @ImPratham45,

Sorry, I didn’t get the expression, Could you please explain the working of this expression.

It will split the string by your keyword
So you will get it in an array
Ex
I am a boy.
If we split by " "
Then we will get array of I,am,a,boy
I.e. length of that array will be 4 and that means our word (here " " ) is comes 3times

1 Like

Ok, got it.

Thank you,
Alamgir

Great!!!