How to use Regex pattern to print all the digits from a string with C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main() {
        string s = "c 5 c++ 9 c# 89 java 334";
  
        foreach (Match m in Regex.Matches(s, @"\d")) {
                Console.WriteLine(m);
        }
    }
}


  
 
  
/*
run:
        
5
9
8
9
3
3
4
    
*/

 



answered Aug 5, 2018 by avibootz
edited Jan 3, 2024 by avibootz

Related questions

...