Olaru Mircea
Olaru Mircea

Reputation: 2620

regex to extract a value from a string

 t=1814994788352,slot=35, cycle=6, nullFrameFlag=0, ppFlag=0, spyFlag=0

I have this line, and using regex i would like to extract the cycle value.

I am trying this but it doesn't work.

Match match = Regex.Match(line, @"cycle=\d,");
if (match.Success)
{
    string key = match.Value;
}

Upvotes: 0

Views: 90

Answers (2)

aelor
aelor

Reputation: 11116

@"(?<=cycle=)\d+"

use this regex. HTH

for further reference , better search for similar questions and learn regex, its helpful.

Upvotes: 3

satnhak
satnhak

Reputation: 9891

Have you tried capturing the value in a group:

Regex.Match(line, @"cycle=(?<cycle>\d),").Groups["cycle"].Value

Not tested the code, but something along those lines should work.

Upvotes: 1

Related Questions