Find a word which appears multiple time in a string

Hello,

I am automating the RZ20 T-code in SAP. In that, on the screen I have to capture the alerts. It may appear 1ce or 2ce or 3ce. Please see the screenshot.

In that alert has appeared 3 times. It may appear 2 times or 1 time. I have to capture those numbers and add them up. How to capture those numbers which will come dynamically. I have used get full text but able to find only 1 alert not the others.

Please help.

Thank you.

If you are able to get the text of the alert, you can use a split function to get the number.
For example,
CInt(text.Split(" "(0))(1))

To get the other lines of text, I’m thinking you need to look at the selector of the Get Text activity and find the value that determines the row. Then, you can grab the other lines by incrementing that row number within the selector expression (click in the selector text box and edit the string).
For example,
“< tablerow:'”+number+“’ >”

Hopefully, this helps you find your answer but I’m not that familiar with the SAP automation, yet.

Thanks.

1 Like

Split(strWord,“Alert”).Length-1

3 Likes

Hey,

Quick question, are you not able to get the text from all 3 rows or don’t know how to parse just the numbers?

If you are able to get the full text that you need, what do you extract it in?

In get full text, I am able to capture all 3 “Alerts” words. I dont know how to capture those numbers. I have tried Index but as it is dynamic it might fail. so now I’m thinking to use Matches and forEach and it is able to capture “Alert” word 2-3 times dynamically correctly but I dont know how to capture numbers attached to it.

This text is not in tabular form.

In get full text, I am able to capture all 3 “Alerts” words. I dont know how to capture those numbers. I have tried Index but as it is dynamic it might fail. so now I’m thinking to use Matches and forEach and it is able to capture “Alert” word 2-3 times dynamically correctly but I don’t know how to capture numbers attached to it.

Then probably your it is ok to go with Regex.Matches and a For Each … something along the lines of Regex.Matches(extractedtext, @“(?<=[\s?)\d{1,}(?=\s?Alerts\s?])”)

ok thanks I applied logic “[([^]]*)]” in Matches and it worked.

1 Like

It did? because “[([^]]*)]” just threw an error on my test :slight_smile:

Also, be careful, your regex will return a collection consisting of
[ 9 Alerts ]
[ 23 Alerts ]
[ 5 Alerts ]
and not just the numbers.

yes I want numbers. Looking for any other expression, the expression you have given did not work for me.

Depending on how the extracted text looks like (i.e if it’s multiline), you may need to use RegexOptions.Multiline parameter, however, regarding the lookup string I gave you, the only error was that I didn’t escape the square brackets. Ie. it should be “(?<=[\s?)\d{1,}(?=\s?Alerts\s?])”

Keep in mind that although this returns only the numbers, you will still have to parse to Int32 :wink:

1 Like

“.(?=.Alerts.)”

check this out

In loop I passed matches again with formula “\d+” and then again loop i took and parsed item into integer and added to another integer variable and it worked out. :slight_smile:
Matches_Regex_Example.xaml (12.7 KB)

thank you for your parse idea. :slight_smile: