正则表达式用途:
(1)验证字符串是否符合指定特征;
(2)查找字符串;
(3)替换。
以下用C#实现上述三种方法的简单示例:
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
   
using System; 
using System.Text; 
using System.Text.RegularExpressions; 
  
namespace CSharpTest 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            Console.WriteLine(new Program().regTest()); 
            Console.ReadLine(); 
        } 
        public String regTest() 
        { 
            String source = " test";
            String result = "正则表达式测试rn"; 
  
            //匹配  
            result += "匹配:" + Regex.IsMatch(source, @"[sS]*?", RegexOptions.IgnoreCase) + "rn"; 
  
            //查找 
            result += "查找:" + Regex.Match(source, @"", RegexOptions.IgnoreCase).Groups[0].Value + "rn"; 
  
            // 替换 
            result += "替换:" + Regex.Replace(source, @"", "", RegexOptions.IgnoreCase) + "rn"; 
            return result; 
        } 
    } 
} 
 | 
	  
	
控制台输出结果:
 正则表达式测试
匹配:True
查找:
替换:
test