Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect number between underscore ("_")?

Tags:

c#

regex

Sorry first, im not good at Regex but anyone can help me ? i have file that named :

Filename - 01.exe

Filename - 001.exe

Filename - 0001.exe

Filename_01_.exe

I have tried with this Regex

(?=.*?)\d{1,4}\b

But that just detect 01, 001, 0001 number at Filename - 01.exe, Filename - 001.exe and Filename - 0001.exe, not worked with Filename_01_.exe Is my Regex is wrong or there Alternative Regex or Method ?

Sorry if my english is not well.

like image 460
deanrihpee Avatar asked Dec 09 '25 07:12

deanrihpee


1 Answers

Since there is only one number in the file, how about simply using this:

\d+

In C#:

var myRegex = new Regex(@"\d+");
string resultString = myRegex.Match(yourString).Value;
Console.WriteLine(resultString);
like image 88
zx81 Avatar answered Dec 10 '25 22:12

zx81



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!