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:
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
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
ppr
(Peter Preuss)
January 19, 2022, 9:17am
3
we can anchor to the word Rack:
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:
for sure we can also finetune to your individual needs
system
(system)
Closed
January 22, 2022, 10:25am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.