Regex to remove all (non numeric OR period)

后端 未结 5 969
陌清茗
陌清茗 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:19

    The regex is:

    [^0-9.]
    

    You can cache the regex:

    Regex not_num_period = new Regex("[^0-9.]")
    

    then use:

    string result = not_num_period.Replace("joe ($3,004.50)", "");
    

    However, you should keep in mind that some cultures have different conventions for writing monetary amounts, such as: 3.004,50.

提交回复
热议问题