Regex to extract account number from a path with specific format

Hi I need to extrac1t account numbers from a path with a specific format:

  1. AccountNumber starts with 123
  2. 12-digit Account number

Input:
/RPA/sample/123456789012/test.xlsx
/RPA/sample/123912213121/test123/test/sample.xlsx
/RPA/sample/012345678910/test.xlsx

Output:
True, 123456789012
True, 123912213121
False

Hi @mnlatam

Instead of regex, could you give this a try

image

and then use the validation

AccNum = Path.GetFileNameWithoutExtension("/RPA/sample/012345678910.xlsx")

flag = AccNum.startsWith("123") And AccNum.Length.Equals(12) And AccNum.IsNumeric

AccNum - String
flag - Boolean

Thanks kumar. the account nos isn’t the filename, hence is a part of the path. I have updated the post

@mnlatam

Using Regex

image

image

Flag = String.IsNullOrEmpty(AccNum)

Note : please import System.Text.RegularExpressions

image

1 Like

Hello @mnlatam , Try this regex expression
(?=123)\d{12}

System.Text.RegularExpression.Regex.Match(YourString,"(?=123)\d{12}").ToString.Trim

Regards,
Gokul Jai

1 Like

a boundary approach option:
grafik

1 Like