[英]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
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. 未经测试的代码,但类似的东西应该起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.