开发者

I want to strip off everything but numbers, $, comma(,)

I want to strip off everything but numbers, $, comma(,).

this only strip letters

        string Cadena;
        Cadena = tbpatronpos6.Text;

        Cadena = Regex.Replace(Cade开发者_开发问答na, "([^0-9]|\\$|,)", "");
        tbpatronpos6.Text = Cadena;

Why doesn't my regex work, and how can I fix it?


I suspect this is what you want:

using System;
using System.Text.RegularExpressions;

class Test
{
    static void Main(string[] args)
    {
        string original = @"abc%^&123$\|a,sd";
        string replaced = Regex.Replace(original, @"[^0-9$,]", "");
        Console.WriteLine(replaced); // Prints 123$,
    }
}

The problem was your use of the alternation operator, basically - you just want the set negation for all of (digits, comma, dollar).

Note that you don't need to escape the dollar within a character group.


you want something like this?

[^\\d\\$,]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜