How to remove numbers from string using Regex.Replace?

前端 未结 6 1989
星月不相逢
星月不相逢 2020-11-30 11:55

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

Example input: 123- abcd33
Example output: abcd

6条回答
  •  野性不改
    2020-11-30 12:44

    As a string extension:

        public static string RemoveIntegers(this string input)
        {
            return Regex.Replace(input, @"[\d-]", string.Empty);
        }
    

    Usage:

    "My text 1232".RemoveIntegers(); // RETURNS "My text "
    

提交回复
热议问题