Get the last value from a string

I am trying to get the last occurrence of the word Rack and the digit after word Rack from a string.
The digit after word Rack sometimes can be more than 2 digit and also sometimes can be 1 digit .
Need help on how to do that.

Example string:


Output should be like:
Rack 10
Rack 22
Rack 1


Use matches activity to extract last two values from a string

put the below regex expression in \w+\s\d+$ value tab and choose regex as advanced


create a output variable for matches activity like RegEx_Out

RegEx_Out(0).ToString holds last two values

use this RegEx_Out(0).ToString where you want to use


we can anchor to the word Rack:

 "ABC Rack 1, And also Rack 22 Other Unforseen Text"
 "Rack \d+"
 myMatches = Regex.Matches(strText, strPattern)
 MatchCollection(2) { [Rack 1], [Rack 22] }
 myMatches.Cast(Of Match).Select(Function (m) m.Value).LastOrDefault()
 "Rack 22"

with a little bit overhead we can grab the last Match, also when it is also not on the Line end

in case of Rack XX is not present we would receive a null without any exception throw:

for sure we can also finetune to your individual needs

This work!
Thank you :slight_smile:

Ypur welcome

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