0

I am doing some data cleaning job where i have to convert pdf file into text using (iText). I need to extract some Data tables out from the parsed. (Tables can appear in any order so could not parse it line by line). Anyways i started looking into regex solution for the same which i thought would be easier but apparently not for me.

The data looks like this

Dummy Value Data
VAL1 VAL2 Mean Calc  Calc2
(mf) (m) (rad) (rad) (rad/100m)
0.0 0.0 0.0 0.0 0.000
9224.0 9224.0 0.0 0.0 0.000
9928.0 9925.9 2.3 322.5 0.490
9885.0 9889.8 0.9 285.9 -0.953
5432.0 5432.5 3.3 95.4 -0.509
<newline>
<newline>

This is exactly the same patter i want to capture. The last 2 new lines mark the end of the pattern. I did tried a few things but nothing worked. I can share my regex too but they dont work.

4

2 回答 2

0

尝试下一个正则表达式:

(\w+( +\w+)*)\r?\n(\w+( +\w+)*)\r?\n(\([\w/]+\)( \([\w/]+\))*)\r?\n((-?\d+\.\d+( -?\d+\.\d+)* *)\r?\n)*(?=(\r?\n){2})

<newline>是在\r?\n正则表达式中。

于 2013-07-03T20:13:42.163 回答
0

您可以使用查找方法

你的正则表达式是

(?<VAL1>[-+]?\d+([.]\d+)?)\s+(?<VAL2>[-+]?\d+([.]\d+)?)\s+(?<Mean>[-+]?\d+([.]\d+)?)\s+(?<Calc>[-+]?\d+([.]\d+)?)\s+(?<Calc2>[-+]?\d+([.]\d+)?)

你的代码

Matcher m=Pattern.compile(aboveRegex).matcher();
while(m.find())
{
    m.group("VAL1");
    m.group("VAL2");
    m.group("Mean");
    m.group("Calc");
}

编辑

匹配多个这样的表

([+-]?\d+([.]\d+)?( [+-]?\d+([.]\d+)?){4}(\r?\n))+(?=(\r?\n))
于 2013-07-03T20:01:10.230 回答