How to find whether a string is a regular expression or normal string in C#. I find in java and PHP but not C#. Can anyone help me please. String testing = "Final";
I want to test whether "testing" is a regular expression or normal string.
Thankyou
How to find whether a string is a regular expression or normal string in C#. I find in java and PHP but not C#. Can anyone help me please. String testing = "Final";
I want to test whether "testing" is a regular expression or normal string.
Thankyou
you can try by exception handling
private static bool IsValidRegex(string input)
{
try
{
Regex.Match("", input);
}
catch (ArgumentException)
{
return false;
}
return true;
}
You can evaulate string in Regex
private static bool IsValidRegex(string pattern)
{
if (string.IsNullOrEmpty(pattern)) return false;
try {
Regex.Match("", pattern);
}
catch (ArgumentException){
return false;
}
return true;
}
If method returns false you can accept this string as normal string.