ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsMatchRegex

Check if a string is match with given regular expression pattern

Source

public static bool IsMatchRegex(this string value, string  pattern)
{
    Regex regex = new Regex(pattern);
    return (regex.IsMatch(value));           
}

Example

string s = "test";
MessageBox.Show(s.IsMatchRegex(@"[a-z]").ToString());

Author: Mohammed Reda AbdulAzim

Submitted on: 14 jan. 2019

Language: C#

Type: string

Views: 4281