Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex searching for string that contains 3 or more digits

Tags:

c#

regex

numbers

I'm trying to find a way to extract a word from a string only if it contains 3 or more digits/numbers in that word. It would also need to return the entire text like

TX-23443 or FUX3329442 etc...

From what I found

\w*\d\w*

won't return the any letters before the dash like the first example?

All the example I found online don't seem to be working for me. Any help is appreciated!

like image 640
mike11d11 Avatar asked Oct 20 '25 04:10

mike11d11


1 Answers

IF I understand your question correctly you wanted to find all the string which contains 3+ consequtive numbers in it such as TX-23443 or FUX3329442 so you wanted to extract TX-23443 and FUX3329442 even if it contains - in between the string. So here is the solution which might help you

string InpStr = "TX-23443 or FUX3329442";
MatchCollection ms = Regex.Matches(InpStr, @"[A-Za-z-]*\d{3,}");
foreach(Match m in ms)
{
    Console.WriteLine(m);
}
like image 116
Mohit S Avatar answered Oct 22 '25 17:10

Mohit S