0

i want parse string like this

  0.1142     0.0000     0.0000     0.0004     0.0000     0.0000    2299/2299        MakeRequest   [23]

I want get ol doubles from this string. I am using next pattern

.+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\.]+) [\\p{Space}]+ ([0-9\\/])+ [\\p{Space}] "\\.(MakeRequest) .+

And this string is parsed well.
But i cann't parse next string!

    20.1600     0.0001     0.0000     0.0053     0.0001     0.0000  383248/383248      MakeRequest   [22]

This string are very similar! But first is parsed, second not:-(

Update Easily pattern

.+ ([0-9\\.]+) .+ ([0-9\\.]+) .+([0-9\\.]+) .+ ([0-9\\.]+) .+ ([0-9\\.]+) .+ ([0-9\\.]+) .+ ([0-9\\/])+ .+\\.(MakeRequest) .+

Don't works too

I'm using

java.util.regex.Pattern

and

java.util.regex.Matcher
1
  • Are there supposed to be two + symbols between the last two groupings? [\\p{Space}]+ + "\\.(MakeRequest) .+? Commented Apr 20, 2012 at 13:06

3 Answers 3

4

([0-9\.]+) .+ ([0-9\/])+

Matches SPACE, ONE OR MORE CHARACTERS, SPACE (total of 3 characters)

Second string has only 2 spaces.

0.0000 383248/383248

Sign up to request clarification or add additional context in comments.

1 Comment

Between the numbers that is, which is where it fails (didn't check if it fails anywhere else too).
2

What would be wrong with code like the following:

  final Matcher m = Pattern.compile("\\d+\\.\\d+").matcher(s); // s is your line
  while (m.find()) System.out.println(Double.parseDouble(m.group()));

Comments

1

This is pattern to get all doubles

[0-9]*\.[0-9]*

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.