How to extract only a part of the text and save it in a variable

Hi Guys!

I have the below filename :
D:\Users\u326509\Documents\UiPath\CSOD_OfferLetter_RE_3\InputFiles\Vigneron Christophe_req5658.xlsm

I need to extract the number 5658 from the filename and use it in the URL below :

Please let me know how to do it.

Hi @Sanghamitra_Sahoo,

More examples are needed to construct an algorithm by understanding the order.

Is the …_[letters][numbers].xlsx format always like this ?


Yes the filename will always be like this format, only the name and the number gets changed.
The number will always be in the last before .xlsm

Some example of other files :

D:\Users\u326509\Documents\UiPath\CSOD_OfferLetter_RE_3\InputFiles\Daron Fillip_req5636.xlsm

D:\Users\u326509\Documents\UiPath\CSOD_OfferLetter_RE_3\InputFiles\Deman Emily_req5591.xlsm

D:\Users\u326509\Documents\UiPath\CSOD_OfferLetter_RE_3\InputFiles\Elsie Soenen_req5364.xlsm

I hope it works for you.

extractData.xaml (5.8 KB)



Try this -

Input_variable = system.text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension("D:\Users\u326509\Documents\UiPath\CSOD_OfferLetter_RE_3\InputFiles\Vigneron Christophe_req5658.xlsm").ToString,"[\d]+").ToString


Check this implementation-

this expression will give you the output all the matched digitis…

@Sanghamitra_Sahoo Try this expression in the regex [\d]{4}[.] and replace the ". ",



Numbers are dynamic it will be of 4 digits or less than it .
Its not a good approach for static regex for 4 digits.

This Works!! Thanks!! :slight_smile:

Hey @Sanghamitra_Sahoo

Take a look here at this 2min tutorial.

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