How to get the last matches of 6 digit number for this pattern \d{6}

i have paragraph and inside that i have more than 5 to 6 lines and inside that there will be many 6 digit numbers and i want to get last number of 6 digit number

@sathish_Kumar6
give me some examples

Here’s how you can implement it in UiPath:

  1. Use the Assign activity to assign your paragraph to a string variable. Let’s call it inputText.
  2. Add the Matches activity to your workflow.
  • Input: inputText (your paragraph)
  • Pattern: \d{6}(?=\D|$) (the regular expression pattern)
  • Result: Create a new variable of type MatchCollection. Let’s call it matches.
  1. Use an If activity to check if matches.Count > 0 (to ensure that there is at least one match).
  2. Inside the If activity, use the Assign activity to assign the last six-digit number to a string variable. Let’s call it lastNumber.
  • Variable: lastNumber
  • Value: matches(matches.Count - 1).Groups(1).Value

The variable lastNumber will contain the last six-digit number found in the paragraph.

1 Like

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"\d{6}",System.Text.RegularExpressions.RegexOptions.RightToLeft)

it might be better the following if there are 7 or more digits number.

System.Text.RegularExpressions.Regex.Match(yourString,"\b\d{6}\b",System.Text.RegularExpressions.RegexOptions.RightToLeft)

Regards,

1 Like

Hello…
System.text.RegularExpressions.Regex.Match(“YourString”,“\d{6}(?=$)”).Value
I hope this will help you or else put the input String I will try.
Thank you.

1 Like

@sathish_Kumar6
Results

1 Like

hi @Yoichi do i need to change variable type or please look into this error?

Hi,

Sorry, it’s my mistake. Can you try to add .Value as the following?

System.Text.RegularExpressions.Regex.Match(yourString,"\d{6}",System.Text.RegularExpressions.RegexOptions.RightToLeft).Value

Regards,

1 Like

Thanks a lot…it worked

im getting empty output for this

Thank you so much for the effor reply @raja.arslankhan

Thanks for the efforts

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