Q:

Using C# Regular expressions how do i match the vertical bar as a literal?

I'm writing a program in C# using Microsoft Visual Studio, i need the program to match the vertical bar, but when I try to escape it like this "\|" it gives me an unrecognized escape sequence error. What am I doing wrong?

A:

In C# 
string test = "\|";

Is going to fail because this is a C# string escape sequence, and no such escape exists.  Because you are trying to include a backslash in the string, you need to escape the slash so the string actually contains a slash:
string test = "\\|";

What will actually be stored in this string is \|

A:

The reason you get an unrecognized escape sequence is that backslash is used as an escape character in C# string literals as well as in regex.
You have several choices to fix this:

Use verbatim literals, i.e. @"\|", or
Use a second escape inside a regular literal, i.e. "\\|", or
Use a character class, i.e. [|]

The third one is my personal favorite, because it does not require counting backslashes.

