c# RegEx with "|"

Posted by WtFudgE on Stack Overflow See other posts from Stack Overflow or by WtFudgE
Published on 2010-03-29T15:09:06Z Indexed on 2010/03/29 15:13 UTC
Read the original article Hit count: 1466

Filed under:
|

I need to be able to check for a pattern with | in them. For example an expression like d*|*t should return true for a string like "dtest|test".

I'm no regex hero so I just tried a couple of things, like:

Regex Pattern = new Regex("s*\|*d"); //unable to build because of single backslash
Regex Pattern = new Regex("s*|*d"); //argument exception error
Regex Pattern = new Regex(@"s*\|*d"); //returns true when I use "dtest" as input, so incorrect
Regex Pattern = new Regex(@"s*|*d"); //argument exception error
Regex Pattern = new Regex("s*\\|*d"); //returns true when I use "dtest" as input, so incorrect
Regex Pattern = new Regex("s*" + "\\|" + "*d"); //returns true when I use "dtest" as input, so incorrect
Regex Pattern = new Regex(@"s*\\|*d"); //argument exception error

I'm a bit out of options, what should I then use? I mean this is pretty basic RegEx i know, but I'm not getting it for some reason..

Thx

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex