正则表达式使用实例 ASP.NET使用正则表达式屏蔽垃圾信息
ASP.NET使用正则表达式屏蔽垃圾信息
找资料 看看如何实现使用正则表达式屏蔽垃圾信息 找来找去找出来的都不怎么好 有不详细的 有代码缺失的 最后还是找到了微软 先摘过来 大概思路已经有了 只需把下面微软给的样例代码修改一下即可 具体能不能行还不知道 先睡一觉 起来再慢慢研究
Regex类
表示不可变的正则表达式
命名空间 System Text RegularExpressions Regex 类包含若干 static(在 Visual Basic 中为 Shared)方法 使您无需显式创建 Regex 对象即可使用正则表达式 在 NET Framework 版中 将缓存通过调用静态方法而编译的正则表达式 而不会缓存通过调用实例方法而编译的正则表达式 默认情况下 正则表达式引擎将缓存 个最近使用的静态正则表达式 因此 在过度地依赖一组固定的正则表达式来提取 修改或验证文本的应用程序中 您可能更愿意调用这些静态方法 而不是其相应的实例方法 IsMatch Match Matches Replace 和 Split 方法的静态重载可用
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{ })?$ );
// Define some test strings string[] tests = { USD };
// Check each test string against the regular expression
foreach (string test in tests)
{
if (rx IsMatch(test))

{
Console WriteLine( { } is a currency value test);
}
else
{
Console WriteLine( { } is not a currency value test);
}
}
}
}
lishixinzhi/Article/program/net/201311/12988