user1761786
user1761786

Reputation: 331

Why did this regex fail to match?

I tested a regex using:

 Match match = Regex.Match(txtToMatch.Text,txtRegex.Text,RegexOptions.IgnoreCase);

 if (match.Success) {               
      MessageBox.Show("success");
 }

The regex that was used was /d. However, when I tested it on 9 it returned false. Why is this so?

Upvotes: 0

Views: 84

Answers (2)

JamesSwift
JamesSwift

Reputation: 863

I think what you need is \d, rather than /d

Upvotes: 3

Douglas
Douglas

Reputation: 54887

You need to use \d, not /d. To avoid getting your string treated as an escape sequence by C#, you could use a verbatim string: @"\d".

Upvotes: 1

Related Questions