locked
Regular Expressions RRS feed

  • Question

  • Hi. Im new to C# and need some help with regular expression.

    Its like this that im trying to delete som of my input text.

    this.richTextBox1.Text = Regex.Replace(this.textBox1.Text, "\\([^(\\r\\n]*\\)", "", RegexOptions.Multiline);

    The input looks smth like this

     Gloves of the Redeemed Prophecy 0.56% (4 in 711)
     Green Qiraji Resonating Crystal 12.24% (87 in 711)
     Yellow Qiraji Resonating Crystal 12.10% (86 in 711)  //This is just an exampel!

    and i want to output only the number.

    so i insert
     Gloves of the Redeemed Prophecy 0.56% (4 in 711)
     Green Qiraji Resonating Crystal 12.24% (87 in 711)
     Yellow Qiraji Resonating Crystal 12.10% (86 in 711)

    and out i want to get

    0.56
    12.24
    12.10

    I have tryed some diffrent things but cant get it to work.
    The code i have now only delete
    (86 in 711)
    (87 in 711) 
    (86 in 711)

    so i want to replace a-z A-Z and % with nothing

    Regards
    //Rickard

    Wednesday, March 8, 2006 6:50 PM

Answers

  • I am sure that a RegEx guru could give you a better answer than me.  With that said, I would use groups to do what you are wanting.  I came up with the following

                Regex regex = new Regex(@"(\d+.\d+)");

                Match match = regex.Match(this.textBox1.Text);

                if (match.Success)
                    Console.Error.WriteLine(match.Groups[0]);
    Wednesday, March 8, 2006 9:55 PM