Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

regex in C#

Using C# and .NET's regex engine, how do I grab a string of digits that are inbetween a pair of double-quotes?

string pattern = @"\"(\d+)\"" doesn't work..  syntax problem...

Thanks for the help.

RAz
Wednesday, June 30, 2004

Regex r = new Regex("\"(\\d+)\"");
You can't use the @ trick if you need to specify special characters like a double quote.

Art Thursland
Wednesday, June 30, 2004

or:

Regex r = new Regex(@"""(\d+)""");

Double the double quotes to put a single literal double quote into the string.

Brad Wilson (dotnetguy.techieswithcats.com)
Wednesday, June 30, 2004

"Double the double quotes to put a single literal double quote into the string."

This is why I feel life is too short to learn RegEx :)

Girb
Wednesday, June 30, 2004

That's actually a C# string-ism.

Brad Wilson (dotnetguy.techieswithcats.com)
Wednesday, June 30, 2004

Awesome.  Thanks

RaZ
Wednesday, June 30, 2004

*  Recent Topics

*  Fog Creek Home