How to get 9 digit and 10 digit number from string

hey all,
i want to get only 9 digit and 10 digit numbers from given string, will share one excel .
example :1] REN_5400804058 DB_0055 output like 5400804058
2]REN 224746296 PRAVIN DHOKE DB0353 output is like 224746296
stmt.xlsx (7.8 KB)

@sayli Please check below regex pattern.



Try this:


System.Text.RegularExpressions.Regex.Matches(str_ex,“^(\d{9}|\d{10})$”) not working for me

1 Like

Here you go
hope its resolved (28.4 KB)
This should be the regex buddy
and the output was

Kindly try this and let know buddy
Cheers @sayli

did that work buddy @sayli

Hello, Use the Split Method
input.Split({" “c,”_"c}) It will separate String based on two characters ( Space and _) and Use Splited(1).ToString in Output.
For more information, watch this video. Let me know if it works.

@sayli you should adjust the expression so it does a negative lookaround for digits on either side.

(?<!\d)\d{9,10}(?!\d) - this should give you all the 9 or 10 digit numbers within the text. It will NOT give you false matches if there is 11 or more digits in a row due to the negative lookaround

1 Like