<p>How do you retrieve selected text using Regex in C#?</p>

<p>I am looking for C# code that is equivalent to this Perl code:</p>

<pre><code>$indexVal = 0;
if($string =~ /Index: (\d*)/){$indexVal = $1;}
</code></pre>

```
```
int indexVal = 0;
Regex re = new Regex(@"Index: (\d*)")
Match m = re.Match(s)

if(m.Success)
  indexVal = int.TryParse(m.Groups[1].toString());
```
```
I might  have the group number wrong, but you should be able to figure it out from here.