c# 正则表达式

来源:互联网 发布:淘宝无线端活动报名 编辑:程序博客网 时间:2024/06/03 22:38

using System; using System.Text.RegularExpressions; public class Test { public static void Main () { // Define a regular expression for currency values. Regex rx = new Regex(@"^-?/d+(/./d{2})?$"); // Define some test strings. string[] tests = {"-42", "19.99", "0.001", "100 USD"}; // Check each test string against the regular expression. foreach (string test in tests) { if (rx.IsMatch(test)) { Console.WriteLine("{0} is a currency value.", test); } else { Console.WriteLine("{0} is not a currency value.", test); } } } }