简体   繁体   中英

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;
}
@"(?<=cycle=)\d+"

use this regex. HTH

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM