Gold Gold - 2 months ago 6
C# Question

How to remove numbers from string using Regex.Replace?

I need to use

Regex.Replace
to remove all numbers and signs from a string.

Example input:
123- abcd33

Example output:
abcd


Thanks in advance.

Answer

Try the following:

var output = Regex.Replace(input, @"[\d-]", string.Empty);

The \d identifier simply matches any digit character.