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 6606497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:24:08+00:00 2026-05-25T19:24:08+00:00

okay so I set up this regex to take exponential and give me back

  • 0

okay so I set up this regex to take exponential and give me back doubles but it crashes if I give it less than two

String sc = "2 e 3+       1";

Pattern pattern = Pattern.compile("\\s+");
Matcher matcher = pattern.matcher(sc);
boolean check = matcher.find();
sc = matcher.replaceAll("");
String sc1;
Pattern p = Pattern.compile("[0-9]+[.]?[0-9]*[eE][-+]?[0-9]+");
Matcher m = p.matcher(sc);
m.find();
int starting = m.start(); //where first match starts
int ending = m.end();//where it ends
String scientificDouble = sc.substring(starting, ending);
String replacement = "" + Double.parseDouble(scientificDouble);
sc1 = sc.replace(scientificDouble, replacement); //first time

//this block must go in a loop until getting to the end, i.e. as long as m.find() returns true
m.find();
starting = m.start(); //where next match starts
ending = m.end();//where it ends
scientificDouble = sc.substring(starting, ending);
replacement = "" + Double.parseDouble(scientificDouble);
sc1 = sc1.replace(scientificDouble, replacement);//all other times,

if I give it sc = “2e3 + 1 ” it crashes saying

Exception in thread "main" java.lang.IllegalStateException: No match available
at java.util.regex.Matcher.start(Matcher.java:325)
at StringMan.main(StringMan.java:32)
  • 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-05-25T19:24:08+00:00Added an answer on May 25, 2026 at 7:24 pm

    To add to @Stephen C’s answer, find() will not magically loop the block of code for you. Since you want to execute the same block of code as long as find() returns true, you should use a while loop:

    String source = "2e3+1, 2.1e+5, 2.8E-2";
    Pattern pattern = Pattern.compile("[0-9]+(\\.[0-9]+)?[eE][\\-\\+]?[0-9]*");
    Matcher matcher = pattern.matcher(source);
    while (matcher.find()) {
       String match = matcher.group();
       double d = Double.parseDouble(match);
       System.out.println(d);
    }
    

    (using regex correctly suggested by @Martijn Courteaux’s answer)

    This particular example prints all parsed double to System.out – you can do what you need with them.

    Please upvote the cited answers if this is helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have this form that is set to preload a DB record
Okay, I've been working through a set of string replacments for bbcode style tags
okay, so I'm trying to set up a webpage with a div wrapping two
Okay, I feel a bit foolish for having to ask this but I guess
Okay I am newer to python and have been researching this problem but I
Okay, I think I might be over-complicating this issue but I truly am stuck.
Okay, so hopefully I am asking this question correctly: I set up my user
Okay I thought this is going to be a piece of cake, but obviously
Okay please help, I've been frustrated with this issue. I need to either set
Okay well I apologize for how sloppy this code is, but I still cant

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.