[英]Extract numbers from string using regex library
So I already know that to get substrings of a string I might use the regex library but the examples I see allows me to get simple substrings.所以我已经知道要获取字符串的子字符串,我可能会使用正则表达式库,但是我看到的示例允许我获取简单的子字符串。
I have this string:我有这个字符串:
string sensorsData = "M -14.520000 -21.180000 -46.139999 A 1.745373 8.829816 4.515464 G -0.244478 0.210922 -0.100135 "
"R 0.509321 0.019607 0.211065 0.834062 g 1.787680 8.412998 4.711269 L - 0.037518 0.426394 - 0.152709 P 5.000000"
"D - 5.496490 - 61.296814 - 21.143848";
What would be the best approach to get every single number from the string?从字符串中获取每个数字的最佳方法是什么? I am using the letters so that I can know what means values.
我使用这些字母是为了知道值的含义。 Thanks.
谢谢。
try this rexEx.试试这个 rexEx。
/-?\\d+\\.*\\d+/
that can capture the numbers you want.可以捕获您想要的数字。
or click this link to see demo.或单击此链接查看演示。
https://regex101.com/r/EfPxHP/1 https://regex101.com/r/EfPxHP/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.