How to extract all digits from string into another string using regex in C#

1 Answer

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

class Program
{
    static void Main() {
        string str = "c# 1 java +746 c++ -2 c 3.14";
        
        string result = Regex.Replace(str, @"[^\d]", ""); 

        Console.Write(result);
    }
}




/*
run:
 
17462314
 
*/

 



answered Jan 3, 2024 by avibootz
edited Jan 3, 2024 by avibootz
...