Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "The name Regex does not exist in the current context" from my C# code?

Tags:

c#

regex

Why am I getting this error:

The name Regex does not exist in the current context.

from my code?

if (Regex.IsMatch(string1, @"^[a-zA-Z]+$"))
like image 720
user2843341 Avatar asked Oct 04 '13 00:10

user2843341


2 Answers

Make sure you have the System.Text.RegularExpressions namespace referenced.

like image 114
Daniel A. White Avatar answered Sep 21 '22 08:09

Daniel A. White


You need to include the right namespace to access the Regex class:

using System.Text.RegularExpressions;
like image 44
codemonkeh Avatar answered Sep 21 '22 08:09

codemonkeh