Need to extract some value from the string

Hi Community,

I’ve a string like this:
“C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf”

I need to extract the number which I mentioned in bold (i.e. 2279260) and this number is dynamic which changes in every run.

PLease suggest .
Thanks.

@siddhi
Try with regex


With Assign Activity

MatchValue=System.Text.RegularExpressions.Regex.Match("C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf", "(?<=_)\d+(?=_)").Value

With Match Activity:

  1. Drag and drop a Matches activity onto your workflow.
  2. In the Properties panel, provide the following values:
  • Input: "C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf"
  • Pattern: (?<=_)\d+(?=_)
  • Result: Create a variable of type System.Collections.Generic.List<UiPath.Match> to store the extracted matches (e.g., named resultList).
  1. Add a For Each activity below the Matches activity.
  2. Set the TypeArgument of the For Each activity to UiPath.Match.
  3. Set the Values property of the For Each activity to resultList.
  4. Inside the For Each activity, you can access each match using the CurrentItem variable.
  5. To extract the desired number, add an Assign activity inside the For Each loop.
  • Left side: Create a variable to store the extracted number (e.g., named extractedNumber).
  • Right side: Assign the value CurrentItem.Value to extractedNumber.

Hi,

\d{7}(?=_PDF)

Thank you

Hi @siddhi
use the below syntax

Assign the path to a variable and use the split to that variable.

variable.split("_"c)(2)

1 Like

Hi @siddhi

HI @siddhi

Try using below expression:

input: “C:\Users\srani\Downloads\R5542565C_MG000003_**2279260** _PDF.pdf”

input.Split("_".ToCharArray).Reverse()(1)

Hope it helps!!
Regards,

first use
str_var= path.getfilenamewithoutextension( “C:\Users\srani\Downloads\R5542565C_MG000003_2279260 _PDF.pdf”)

str_var = str_var.split("_"c)(2).tostring

try this

1 Like

Thanks everybody for the response.

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