regular expression 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/05/18
6:00 UTC
Read the original article
Hit count: 407
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 regular expression 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 a pretty basic regular expression I know, but I'm not getting it for some reason.
© Stack Overflow or respective owner