I have string and i want always to extract only last time

"1m53s1m38s1m47s1m3s49s53s1m4s1m0s2m27s"I have this string and i want always to extract only last time which is 2m27s but this time is always changing sometimes with ddmdds and somtimes dmds or ddmds and so on , How to achieve that in UiPath studio

Hi @rawanghurab1

Try this

"\d+m\d+s"
Matches.Last

Cheers!!

Might be any variable is holding this string value, You have to make a Assign Activity which holds this Right(YourVariableName_WhichHoldStringValue,5) and call this value into Message Box or Log Message activity.

Like this,

image

I hope this is helpful to you.
Akhil

I Appreciate it, but using Rejex might be the last option when we’re building a project.
This statement is from my Mentor.

Hi @rawanghurab1
you can use regex it will get last time from any chaning time.

System.Text.RegularExpressions.Regex.Match(text, “\d{1,2}m\d{1,2}s(?:(?!.\d{1,2}m\d{1,2}s).$)”).Value

image

image
image

image
image

Hi @rawanghurab1

You can use the below expression to get the last time from the Input String, Store the input data in a variable called Input.

- Assign -> Input = "1m53s1m38s1m47s1m3s49s53s1m4s1m0s2m27s"

- Assign -> Output = System.Text.RegularExpressions.Regex.Matches(Input.toString, "\d+m?\d+s?").Cast(Of Match)().Last.toString

Check the below workflow for better understanding,

Hope it helps!!

Hi @rawanghurab1 ,

regular Expression used in Matches Activity is
“\d+m\d+s”

Matches Activity will generate a output of type IEnumerable

To get the Last Value :
Op_Regex.Last.ToString



image

Hope this helps you out.

Happy Automating…!

Thanks,
Gautham.

Thank you for your support but What if the last time only have s like 45s without m?

Hi @rawanghurab1

In that case you can try this

\d+m?\d+s?

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