Regular Expression Issue while retrieving from database table

We have regular expression value @"^[a-zA-Z0-9_]*$ in database table for nvarchar column . When we are retrieving expression from database table than we are getting expression value with special char like @"^[a-zA-Z0-9_]*$"

This value is not evaluated . How I can ensure

  • regular expression is valid expression

  • How I can remove special char while getting expression values from database table.

This is the code:

public static bool IsMatch(string target, string pattern, RegexOptions options) {
    if (String.IsNullOrEmpty(target)) {
        throw new ArgumentNullException("target");
    } if (String.IsNullOrEmpty(pattern)) {
        throw new ArgumentNullException("pattern");
    }
    return Regex.IsMatch(target, pattern, options);
}

Source: New Questions

Leave a Reply