Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match all digits but splitted in single characters

Tags:

c#

.net

regex

This is my string:

Hello world, '4567' is my number.

If /g (global modifier) was supported in .NET, There was no problem to get what I want, but now, I don't know what to do and need your help. I need match all digits (4567) but splitted in single characters. I want it like this:

match 1: 4, match 2: 5, match 3: 6, match 4: 7

Thanks, Alireza

like image 523
Alex Avatar asked Jan 11 '23 06:01

Alex


1 Answers

You can use Regex.Matches to get all the matches i.e. digits in your case.

var matches = Regex.Matches("Hello world, '4567' is my number.", "\\d"); 
    foreach(Match match in matches)
       Console.WriteLine(match.Value);
like image 196
Adil Avatar answered Jan 15 '23 11:01

Adil