Really simple regex problem

  • Thread starter Thread starter mikeachamberlain
  • Start date Start date
M

mikeachamberlain

Hello there.

This should be very simple for someone to solve.

string s = System.Text.RegularExpressions.Regex.Replace(
"King Henry Viii", "\bViii\b", "VIII");
Console.WriteLine(s);

I think the above code should write out the string "King Henry VIII"
(with capital I's), but instead it writes the original input string
unchanged. If I remove both (but not either) of the word boundary meta
characters then it works as expected. Could someone show me where I am
going wrong?

Cheers,

Mike
 
The Regex is fine; the problem is the C# - specifically the character
escaping; just add @...

@"\bViii\b"

Marc
 

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

Back
Top