Extracting groups from money matches : 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 r = new Regex(@"\$((\d{1,3},)*\d+)\.(\d{2})");
        Match m = r.Match("$1,035.66,100.99");
        Console.WriteLine("Dollar part: {0}, cents: {1}",
            m.Groups[1].Captures[0].Value, m.Groups[3].Captures[0].Value);
   }
}
Dollar part: 1,035, cents: 66








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