472,328 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 12259
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Theo Chakkapark | last post by:
I'm having issues trying to replace text with PHP. For example, if I have a string of text that reads: {tag} And want to replace that with:...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&") Regex.Replace(Subject, "\'", "'") ...
3
by: Roger | last post by:
I'm having a little trouble using the Regex.Replace method. I am trying to perform a search and replace based on string pattern. I've been...
1
by: justin.mayes | last post by:
hello all - An example. You have a regular expression to locate certain html tags. "(<)" This will find every instance of a "<" character...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space...
2
by: Jeremy | last post by:
I am trying to replace a string "P" with "\P" as long as the string "P" does not already have a "\" in front. for my search string I've used...
5
by: Alan M Dunsmuir | last post by:
I am confused by the operation of the RegEx Replace functions provided by PHP. I understand, of course, what is intended if the 'Replace' string...
1
by: Sal Sal | last post by:
I am using System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, options) in c# to replace the input string. The pattern I am...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.