The case of the sneaky backslash - Regex
Posted
by Shane Cusson
on Stack Overflow
See other posts from Stack Overflow
or by Shane Cusson
Published on 2010-05-17T22:28:38Z
Indexed on
2010/05/17
22:30 UTC
Read the original article
Hit count: 256
I'm missing something very obvious here, but I just cant see it.
I've got:
string input = @"999\abc.txt";
string pattern = @"\\(.*)";
string output = Regex.Match(input,pattern).ToString();
Console.WriteLine(output);
My result is:
\abc.txt
I don't want the slash and cant figure out why it's sneaking into the output. I tried flipping the pattern, and the slash winds up in the output again:
string pattern = @"^(.*)\\";
and get:
999\
Strange. The result is fine in Osherove's Regulator. Any thoughts?
Thanks.
© Stack Overflow or respective owner