Search code examples
c#regexreplaceall

regex expression help for two or more decimal places


Using c# I am trying to replace text in richtextbox that has two or more decimal places. In particular I am looking for Regex expression for two to four decimal places.

if someone can assist with this. I would appreciate it. I tried numerous regex expression, most of which did not work


Solution

  • \d+\.\d{2,4} will match numbers with two to four decimals.
    \d+\.\d{2,} will match numbers with two and more decimals.

    Note that you should not use regex here if you can avoid. You will disregard localization and won't easily be able to round (if that's what you want).