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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:09:11+00:00 2026-05-31T11:09:11+00:00

I need to split a string that is going to be the input of

  • 0

I need to split a string that is going to be the input of a calculator. I want to split it into two arrays using the split function in java. The first array should only have the numbers of the string (this includes numbers with decimal places). The second should only include the mathematical operators like “+-*/”. Currently this is my code:

String[] numbers = s.split("[[+-/*]&&[^.]]");
String[] operators = s.split("[^*/+-]");

I seem to be able to split the string into the seperate numbers array perfectly fine (even with decimal points), but I can’t seem to be able to split the string into the separate operators if there is a decimal point anywhere with the numbers (it works otherwise though).

Ex: I want “9.0/3+2.3” to become {/,+}.

What should I change my regex (for the second line of code) to be to get my desired output? Everything I’ve tried hasn’t worked.

  • 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-31T11:09:12+00:00Added an answer on May 31, 2026 at 11:09 am

    Try this:

    String[] numbers = s.split("[[+-/*]&&[^.]]");
    
    ArrayList<String> ops = new ArrayList<String>();
    for (String op : s.split("[^*/+-]"))
        if (!op.isEmpty())
            ops.add(op);
    String[] operators = ops.toArray(new String[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that I need to be split into 2. I want
I need to split my string input into an array at the commas. Is
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I have a very long string that I want to split into 2 pieces.
I need to split a string into chunks of 2,2,3,3 characters and was able
In C# I need to split a string (a log4j log file) into array
What regex pattern would need I to pass to java.lang.String.split() to split a String
I have a long string (multiple paragraphs) which I need to split into a
I have a string that I need to split on a certain character. However,
I have limited JS experience, and I need to split a string that would

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.