Help converting C# Regular Expression to VB.Net??

A

alexstevens

Hi All.

I'm using some C# code which I translated to vb.net to remove
sourcesafe information from project and solution files. It uses regular
expressions, and the attempt I made at translating the c~ expression
doesn't produce the required results.....

Could some have a look at this and point out where I've gone wrong?

C# Code:
Regex r = new Regex("\\\"Scc\\w*\\\"\\s*=\\s*\\\".*\\\"");

and my stab at VB.Net Code:
Dim objRegEx As New Regex("\\""Scc\w*\\""\s*=\s*\\"".*\\""")

and a second expression:


C# Code:
Regex r = new Regex("Scc\\w*\\s*=\\s*\\\".*\\\"");

and my stab at VB.Net Code:
Dim objRegEx As New Regex("Scc\w*\s*=\s*\\"".*\\""")

Thanks

Alex
 
J

Joshua Flanagan

Its a little tricky not knowing your original intended expression, but
I'll take a stab.

My guess at the VB.NET for the first one would be:
New Regex("\""Scc\w*\""\s*=\s*\"".*\""")

and the second:
New Regex("Scc\w*\s*=\s*\"".*\""")

Note, C# uses \" to represent " while VB.NET uses ""
And C# uses \\ to represent \ while VB.NET does not need to escape a \

If you don't want to escape \ in C#, you can add a @ before the string.
For example:
Regex("\\w*")
can be re-written as
Regex(@"\w*")


Hope that helps.

Joshua Flanagan
http://flimflan.com/blog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top