Hi I need to extrac1t account numbers from a path with a specific format:
AccountNumber starts with 123
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
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
Flag = String.IsNullOrEmpty(AccNum)
Note : please import System.Text.RegularExpressions
1 Like
Hello @mnlatam , Try this regex expression
(?=123)\d{12}
System.Text.RegularExpression.Regex.Match(YourString,"(?=123)\d{12}").ToString.Trim
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
Regards,
Gokul Jai
1 Like
ppr
(Peter Preuss)
August 31, 2022, 11:39am
6
a boundary approach option:
1 Like