Extracting a number that is to the left of a specific string

Hello! Say I have a string with multiple text and number values. How would I extract the number to the LEFT of a specific text, “Menu” ?

we can use this expression

Cheers @Hisuhong

Ah I forgot to give an example of the string.

It’s a string like this. I want to extract the number to the left of the text “Menu”, which in this case is “01”. This is necessary because this number changes for different accounts but the text stays the same. How would I extract the number in this case? @Palaniyappan

1 Like

yah get this as a string using screens scrapping method and store that in a string varaible named str_input
–now use this expression
str_output = System.Text.RegularExpressions.Regex.Matches(str_input,"^[\d]+")(0).ToString \\if we want only 01

and if we want all the numerical values in the left side then
the expresssion would be
list_matches = System.Text.RegularExpressions.Regex.Matches(str_input,"^[\d]+").ToString

where list_matches is a variable of type

then use FOR EACH loop activity and pass the variable list_matches as input and channge the type argument as string in the property panel
–insiide the loop use writeline activitty and mention as
which will display all numerical value one by one

Cheers @Hisuhong

I’m still very unfamiliar with regex so I tried the following: myString.Substring(myString.IndexOf(“Menu”)).Split(environment.NewLine.ToCharArray)(0)

Except that just returns “Menu”. Do you know how to isolate the number using this method? or even the line that contains both “Menu” and “01”?

Oh never mind, I figured out how to do it. Thank you for your help! @Palaniyappan

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.