Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:51:34+00:00 2026-06-17T10:51:34+00:00

I am trying to parse doubles from a line of text. I found few

  • 0

I am trying to parse doubles from a line of text. I found few lines of code that I thought was doing what I wanted. However, I discovered it would not parse negative doubles (would just parse them as positive). I am totally new to regex and its a little overwhelming. I was wonder if someone could explain the code below and tell me what each part means, and how I would modify it so it will parse both positive and negative doubles? Thanks in advance!

double nextDouble;
Matcher matcher = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(line);
if (matcher.find()) nextDouble = Double.parseDouble(matcher.group(1)));

EDIT: Here is an example of a line.
“104.44518717, 34.09785265, 103.39288764, 0.09813121, 0.00000000, -0.46612322, 4.68576504”

It parses -0.46612322 as 0.46612322.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:51:35+00:00Added an answer on June 17, 2026 at 10:51 am

    The expression you have has two parts.

    The fist part in the brackets is ensuring that the matching string isn’t preceded by digits
    and points. Not sure why you need that part, if you provide a sample line that would help.

    The second part in the brakets is the matching part. That just says match 1 or more digits and points.

    If you want to make your expression to work with negative numbers you can just add the ‘-‘ character to the matching set.

    (?!=\\d-\\.)([-\\d\\.]+) 
    

    But this, as well as your expression will match strings with multiple points(dots). Eg 122.12.12

    So I suggest you try the following. Note that i removed the first part.

    (-?(\\d)+(\\.)?(\\d)*)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse an HTML document and extract some elements (any links to text
I am trying to populate combo boxes from a text file using comma as
I am trying to parse the JSON results from an AJAX call, but do
I'm trying to serialize properties of a class that inherits from another using Reflection,
I'm trying to read data values from a text file and store them in
I have a flat file of e-mail header data that I'm trying to parse
I'm reading from an xml file and trying to parse the data to a
I'm trying to parse a multipart/form-data request properly, it works unless the file that
Following on from a previous post , I've found I'm totally stuck. I'm trying
I am trying to read from a file that has comma seperated values like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.