Resolved Stumped: Regex works in C# but not VB

BrianBu

New member
Joined
Jan 12, 2010
Messages
3
Programming Experience
10+
I'm working through the Pro ASP.NET MVC Framework book by Apress (which is great, btw) and it's in C# although we mostly work in VB so I'm "translating" the examples along the way. So far so good but I ran into something that has thrown me.

Long story short we need to validate that the string the user gave us as an email address. This returns true in C#:

Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch("Me@me.com", ".+\\@.+\\..+"));

But this returns false in VB:
Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch("Me@me.com", ".+\\@.+\\..+"))

I'm sure I'm missing something small but it's giving me heartburn. Thanks in advance for any help.
 
Last edited:
\\ looks for \ , @ does not need a literal lookup which is what the \ is for when it is not a normal parser following it. ".+@.+\..+" finds the string 'Me@me.com'. Notice how we need a literal lookup for the '.' - that is because it is a parser object.
 

Latest posts

Back
Top