469,917 Members | 1,891 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

regex replace pipe character

I am having trouble removing a pipe character using Regex.Replace -
see the 2 NUnit tests below:

The first replace works fine and the second Replace does not work.
I've tried escaping the pipe character.

Can anyone get this to work?

Thanks

Glenn

using System;
using NUnit.Framework;
using System.Text.RegularExpressions;

namespace ScratchPad
{
[TestFixture] public class ScratchPad
{
[Test] public void RegexReplace_o()
{
Regex r = new Regex("bob");
Match m = r.Match("bob");
Assert.AreEqual(true,m.Success);
Assert.AreEqual("bb",Regex.Replace("bob","o",""));
}
[Test] public void RegexReplace_bar()
{
Regex r = new Regex("b|b");
Match m = r.Match("b|b");
Assert.AreEqual(true,m.Success);
//Assert.AreEqual("bb",Regex.Replace("b|b","|",""));

}
}
}
Nov 17 '05 #1
1 11574
> I am having trouble removing a pipe character using Regex.Replace -
see the 2 NUnit tests below:

The first replace works fine and the second Replace does not work.
I've tried escaping the pipe character.

Can anyone get this to work? Regex.Replace("b|b","|",""));


Regex.Replace("b|b",@"\|","") // works for me

--

www.midnightbeach.com
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Theo Chakkapark | last post: by
3 posts views Thread by Roger | last post: by
3 posts views Thread by Pascal | last post: by
2 posts views Thread by Jeremy | last post: by
5 posts views Thread by Alan M Dunsmuir | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.