obpax
obpax

Reputation: 1

Regex match is null

I have:

string cap = "OK|pz6u1";
var id = Regex.Match(cap, @"OK\|(.*?)").Groups[1].Value;

Why id is null?­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

Upvotes: 0

Views: 682

Answers (1)

Piotr Stapp
Piotr Stapp

Reputation: 19830

change your code to below one:

var id = Regex.Match(cap, @"OK\|(.*)").Groups[1].Value

The problem in your expression was a question mark (?). Question mark mark makes the previous statement optional, so that is way it was omitted.

Upvotes: 1

Related Questions