如何验证正防爆pression? [英] How to validate a Regular Expression?
本文介绍了如何验证正防爆pression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发的.NET应用程序,用户可以提供事后被用来验证输入数据的普通防爆pressions。
I'm developing an application in .NET where the user can provide Regular Expressions that are afterwards used to validate input data.
我需要一种方法来知道,如果一个普通的前pression实际上是适用于.NET正则表达式引擎。
I need a way to know if a regular expression is actually valid for the .net regex engine.
感谢您的帮助
推荐答案
只是试图编译给定的正则表达式。你可以通过创建正则表达式对象,并传递模式给它。下面是一个示例code:
Just try to compile the given regex. You can do that by creating the Regex object and passing the pattern to it. Here's a sample code:
public static bool IsRegexPatternValid(String pattern)
{
try
{
new Regex(pattern);
return true;
}
catch { }
return false;
}
这篇关于如何验证正防爆pression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文