Matching money: \$(((\d{1,3},)+\d{3})|\d+)\.\d{2} : Regex Money « Regular Expression « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;

public class MainClass{

   public static void Main(){
        Regex moneyR = new Regex(@"\$(((\d{1,3},)+\d{3})|\d+)\.\d{2}");
        string[] money = new string[] { "$0.99", 
                                        "$1099999.00", 
                                        "$10.25", 
                                        "$90,999.99", 
                                        "$1,990,999.99", 
                                        "$1,999999.99" };
        foreach (string m in money){
            Console.WriteLine(m);
            Console.WriteLine(moneyR.IsMatch(m));
        }
   }
}
$0.99
True
$1099999.00
True
$10.25
True
$90,999.99
True
$1,990,999.99
True
$1,999999.99
False








17.7.Regex Money
17.7.1.Matching money: \$\d+\.\d{2}
17.7.2.Matching money: \$(\d{1,3},)*\d+\.\d{2}
17.7.3.Matching money: \$(((\d{1,3},)+\d{3})|\d+)\.\d{2}
17.7.4.Extracting groups from money matches