ASP.NET使用正则表达式屏蔽垃圾信息分享


Regex 类
表示不可变的正则表达式。
命名空间:System.Text.RegularExpressions
Regex 类包含若干 static(在 Visual Basic 中为 Shared)方法,使您无需显式创建 Regex 对象即可使用正
则表达式。在 .NET Framework 2.0 版中,将缓存通过调用静态方法而编译的正则表达式,而不会缓存通过调
用实例方法而编译的正则表达式。默认情况下,正则表达式引擎将缓存 15 个最近使用的静态正则表达式。因
此,在过度地依赖一组固定的正则表达式来提取、修改或验证文本的应用程序中,您可能更愿意调用这些静态
方法,而不是其相应的实例方法。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{2})?$”);
// Define some test strings.
string[] tests = {“-42”, “19.99”, “0.001”, “100 USD”,
“.34”, “0.34”, “1,052.21”};
// 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);
}
}
}
}

—-想了解更多的linux相关异常处理怎么解决关注<计算机技术网(www.ctvol.com)!!>



本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/htmltutorial/75968.html

(0)
上一篇 2020年4月20日
下一篇 2020年4月20日

精彩推荐