正则表达式,在这种情况下如何提取值 [英] Regex, how to extract the values in this case
本文介绍了正则表达式,在这种情况下如何提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个像这样的文本文件:
Hi everyone,
I have a text file like this one:
"Begin of data
ID Value1 Value2
8.556 80021296 338.10 A
337.20 A
12.066 4998751 846.70 B
14.034 3584897 729.20 A
365.15 C
345.66 A
End of data"
每个ID将有1个Value1和一些Value2。我需要使用value1和value2提取每个ID。 ID的数量也有所不同。我怎么能用正则表达式做这个?
我尝试过:
我尝试了一些正则表达式模式,但无法使其工作。
Each ID will have 1 Value1 and some Value2. I need to extract each ID with its value1 and value2. And the number of ID varies too. How can I do this with Regex?
What I have tried:
I tried with some Regex patterns but unable to make it work.
推荐答案
这将取决于你想要的数据:如果它;只是完整行:
That's going to depend on what data you want: if it;s just the "full lines":
8.556 80021296 338.10 A
12.066 4998751 846.70 B
14.034 3584897 729.20 A
然后它相对简单:
Then it's relatively simple:
^(?<ID>\d+\.\d+)\s+(?<Value1>\d+)\s+(?<Value2>\d+\.\d+)\s.*
如果你想要其他线路,你最好使用string.Split并自己解析...
If you want the other lines, you are better off using string.Split and parsing it yourself ...
这篇关于正则表达式,在这种情况下如何提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文