Johan
Johan

Reputation: 35194

Extracting digits from string

I'm trying to extract some digits from a string: foo=bar&hash=00000690821388874159\";\n

I tried making a group for the digit, but it always return an empty string.

string matchString = Regex.Match(textBox1.Text, @"hash=(\d+)\\").Groups[1].Value;

I never use regex, so please tell me what I'm missing here.

Upvotes: 0

Views: 121

Answers (1)

dee-see
dee-see

Reputation: 24078

There is no \\ in your string, the \ is in fact used to escape a quote so that's why the regex doesn't match. This works:

string matchString = Regex.Match(textBox1.Text, @"hash=(\d+)""").Groups[1].Value;

http://dotnetfiddle.net/2U0lkI

Upvotes: 6

Related Questions