[英]regex to match only decimals after a colon
I'm real close but I'm not a regex expert. 我真的很亲密,但我不是正则表达式专家。 Here's my input strings.
这是我的输入字符串。
DCIN : 11.896V
5V : 4.988V
Vcom : 0.008V
5VStby: 4.992V
48V : 0.042V
48I : 0mA
I want only the numeric values after the colon. 我只需要冒号后面的数值。 This is what I have so far
这就是我到目前为止
/[^\D]+\.?[^\D]+/
and it's also grabbing the two 48 instances and it isn't getting the 0 而且它同时捕获了两个48个实例,但没有得到0
Your regex requires at least 2 digits on end, that is why it does not match the zero on the last line, and there is no restriction in your pattern to only match after a colon. 您的正则表达式至少需要2位数字,这就是为什么它与最后一行的零不匹配的原因,并且您的模式没有限制,只能在冒号之后匹配。
Use 采用
var res = Regex.Matches(s, @":\s*(\d*\.?\d+)")
.Cast<Match>()
.Select(m=>m.Groups[1].Value)
.ToList();
See the regex demo 见正则表达式演示
Details : 详细资料 :
:\\s*
- a colon and zero or more whitespace :\\s*
-一个冒号和零个或多个空格 (\\d*\\.?\\d+)
- Capturing group 1 holding the value you need: (\\d*\\.?\\d+)
-捕获包含所需值的组1:
\\d*
- zero or more digits \\d*
-零个或多个数字 \\.?
- an optional dot \\d+
- one or more digits. \\d+
-一个或多个数字。 我愿意做这个
^[^:]*:\s*(\d+(?:\.\d*)?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.