Get the last value from a string

Hi,
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:

image

Output should be like:
Rack 10
Rack 22
Rack 1

Hi @NAJAA_BAZILAH

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


image

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

Thanks
Robin

we can anchor to the word Rack:
grafik

 strText
 "ABC Rack 1, And also Rack 22 Other Unforseen Text"
 strPattern
 "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:
grafik

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.