Regex help

G

Guest

I'm new at using Regex, and I'm using VB.NET.
I can't seem to get this to work. I'm replacing matched items in a text file.
The format is v (upper or lower) and then 4-5 integers.
I'm trying (many variations of):

'Replace version
newText = Regex.Replace(contents, "(\bv)([0-9]{4,5})", VersionNew,
RegexOptions.Multiline)

where; newVersion is just a string, and contents is the stream of the text
I can get this to work if I 'hard code' the item to replace in the file, but
I want to use regex since this might change.

I've been using 'http://regexlib.com/RETester.aspx' to help build the
expression.
All the examples are in C#, and whne I convert the characters '@' is not
recongized?

Help?
 
G

Guest

Here is a sample from some work I just did.

string pattern = @"( xmlns=\"")(.*)(\"")";
_logFileText = Regex.Replace(_logFileText, pattern, string.Empty);

I am not quite sure what you are referring to regarding the "@", but here is
an example of what I believe is called string literal. Sometimes you have to
use a string literal to get the escape characters to work properly.
 
F

Flinky Wisty Pomm

If I'm not mistaken, the parentheses set up a match group - you want to
match a V01234, but you're actually matching the V and the digits
separately. Have you tried "v\d{4,5}" ? Don't forget to use
RegexOptions.IgnoreCase.

Are you intending to match the two parts separately?

The @ tells the C# compiler to treat everything inside the quotes as
literal text, otherwise in the example above, it would first try to
convert \d to an escaped character and choke horribly.
 

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

Similar Threads

Regex replace problem 2
My regex kung-fu is not strong =( 0
Creating a regex to get multiple values and print 0
RegEx Help 2
Help for a newbie 13
Regex 3
Python battle game help 2
Regex Question 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top