locked
Remove all non-digit except some

    Question

  • Hello

    There are thousand of site explaining how to use regexp with many pages of tutorial. Each time I feel that a regexp would be usefull I conclude that it will be faster to write a little csharp method than spending hours to try to learn regexp !

    However learn by example is often faster than having to read a book

    But I did'nt find any good blog showing a list of common (and more exotic) regexp with purpose

    Waiting for a genius to do that !

    My concern now is to remove all non digit from a string, except semi-column

     


    olibara
    Wednesday, May 12, 2010 7:48 PM

Answers

  • write some examples of your sample data and what you want eliminated. 

    String word = "K2AB2365478962593";
    word = Regex.Replace(word, @"\D", "");
    Console.WriteLine(word);
    Console.ReadLine();


    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Wednesday, May 12, 2010 9:21 PM
  • Hi,

    You can use:-

    Dim word As String"amb@!;1c23"

    word = Regex.Replace(word, "[^0-9^;]", "")

    Response.Write(word)

    You can follow this link too:- http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm

    Thanks,

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Thursday, May 13, 2010 10:51 AM
  • My concern now is to remove all non digit from a string, except semi-column


    I will assume you mean semi-colon, as I don't know how to remove a semi-column using regular expressions.

    But here's one code snippet that should do that:

    ---------------------------------------
    Dim myRegExp, ResultString
    Set myRegExp = New RegExp
    myRegExp.Global = True
    myRegExp.Pattern = "[^\d;]"
    ResultString = myRegExp.Replace(SubjectString, "")
    -----------------------------------------

    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Friday, May 14, 2010 12:48 AM
  • Hi Olivier,

        Just answer the first part of your question. The following references could be helpful.

        1. Regular Expressions by Category

        2. Tools like Regulator and Expresso that allow you to design, test, search for regular expressions.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by SamAgain Friday, May 14, 2010 2:46 AM
    Friday, May 14, 2010 2:46 AM

All replies

  • write some examples of your sample data and what you want eliminated. 

    String word = "K2AB2365478962593";
    word = Regex.Replace(word, @"\D", "");
    Console.WriteLine(word);
    Console.ReadLine();


    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Wednesday, May 12, 2010 9:21 PM
  • Hi,

    You can use:-

    Dim word As String"amb@!;1c23"

    word = Regex.Replace(word, "[^0-9^;]", "")

    Response.Write(word)

    You can follow this link too:- http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm

    Thanks,

    Amit

    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Thursday, May 13, 2010 10:51 AM
  • My concern now is to remove all non digit from a string, except semi-column


    I will assume you mean semi-colon, as I don't know how to remove a semi-column using regular expressions.

    But here's one code snippet that should do that:

    ---------------------------------------
    Dim myRegExp, ResultString
    Set myRegExp = New RegExp
    myRegExp.Global = True
    myRegExp.Pattern = "[^\d;]"
    ResultString = myRegExp.Replace(SubjectString, "")
    -----------------------------------------

    • Marked as answer by SamAgain Friday, May 14, 2010 2:38 AM
    Friday, May 14, 2010 12:48 AM
  • Hi Olivier,

        Just answer the first part of your question. The following references could be helpful.

        1. Regular Expressions by Category

        2. Tools like Regulator and Expresso that allow you to design, test, search for regular expressions.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by SamAgain Friday, May 14, 2010 2:46 AM
    Friday, May 14, 2010 2:46 AM