user1762109
user1762109

Reputation:

Using "@" in regular expression with VB.NEt

Assuming I have to check if "@" exists on a given string - should I use back slash before or not? So far I found they're both working for me, but I'm not sure if it always works on any Windows host (this is part of a VB.NET application that has to work world-wide)

The string: Hello @world

Pattern1: Hello @world

Pattern 2: Hello \@world

Which one should I use to get the most precise matching? pattern1 or pattern2?

I work with VB.NET on VS2010 (.NET FW 3.5)

Thank you

Upvotes: 0

Views: 71

Answers (2)

Andrei
Andrei

Reputation: 56716

@ is not a special regex character, at least not in VB.NET. Which means that both patterns are pretty much the same, and you can use whichever you prefer. Although for readability sake you probably should stick to the pattern without backslash.

You can find complete list of special regex characters in .NET here.

Upvotes: 1

NeverHopeless
NeverHopeless

Reputation: 11233

I would suggest you to leave this option on Regex engine. Just use its Regex.Escape function. It will escape the necessary things.

Upvotes: 0

Related Questions