Regex to remove all (non numeric OR period)

后端 未结 5 1018
陌清茗
陌清茗 2021-02-02 04:46

I need for text like \"joe ($3,004.50)\" to be filtered down to 3004.50 but am terrible at regex and can\'t find a suitable solution. So only numbers and periods should stay -

5条回答
  •  忘掉有多难
    2021-02-02 05:34

    You are dealing with a string - string is an IEumerable, so you can use LINQ:

    var input = "joe ($3,004.50)";
    var result = String.Join("", input.Where(c => Char.IsDigit(c) || c == '.'));
    
    Console.WriteLine(result);   // 3004.50
    

提交回复
热议问题