I'm developing an application in .NET where the user can provide Regular Expressions that are afterwards used to validate input data.
I need a way to know if a regular expression is actually valid for the .net regex engine.
Thanks for any help
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With