Remove numbers from string regex

Posted on 2009-12-22
Last Modified: 2012-05-08
I need to remove numbers from strings like



so that i end up with

Data and DateLast

Using c# regex...
Question by:JonMny
    LVL 27

    Accepted Solution


    using System;
    using System.Text.RegularExpressions;
    namespace myapp
      class Class1
          static void Main(string[] args)
              String sourcestring = "Data123";
              String matchpattern = @"\d+";
              String replacementpattern = @"";

    Open in new window

    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi JonMny;

    When using the Regex.Replace method you need to assign the return value of that function to a variable or itself as shown below.

    List<string> stripdigits = new List<string>();

    for (int idx = 0; idx < stripdigits.Count; idx++)
        stripdigits[idx] = Regex.Replace(stripdigits[idx], @"\d+", String.Empty);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now