c# RegEx with "|"
- by WtFudgE
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