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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:08:09+00:00 2026-06-18T14:08:09+00:00

I have a text-box in which the input is a simple math expression like

  • 0

I have a text-box in which the input is a simple math expression like 2+323*4.5/5 or 2 + 323*4.5 /5 (I mean the white spaces should be ignored). Both integers and floats are possible and acceptable as input. I want to break apart every element of this expression (both operands and operators) and save them into an array, so that I can send the first operand, the first operator, and the second operand (as parameters of an atomic calculation) to a PHP page (server) and then after getting the server’s response, send the second operator and the third operand together with the server’s previous response in order to perform another atomic operation and so on.

For example, if the initial string is 2 + 323*4.5 /5, my array (the result) should look like this:

[2, +, 323, *, 4.5, /, 5].

I used the match method as follows:

var expr = document.getElementById("txtExpr").value; 
var tokens = expr.match(/-*\/?[0-9]/g);

But I can’t use “+” sign and the result array is not what I’m looking for. It concatenates the operator to the next operand.

PS: I NEED TO ACCEPT/GET NEGATIVE NUMERS AS WELL.

  • 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-18T14:08:11+00:00Added an answer on June 18, 2026 at 2:08 pm
    "2 + 323*4.5 / 5".match(/\d*\.\d+|\d+|[/*+-]/g);
    // >> ["2", "+", "323", "*", "4.5", "/", "5"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text-box into which a user can input a comment. The comment
At the moment I have a slider and an small input text box which
Lets say I have a text box which should have a default value.... and
I have a custom text box control which validates input (striped out unwanted chars).
I have a simple ASP.Net MVC View which contains an FCKeditor text box (created
I have a simple label, and a number input box: The code for which
I have a text input box exactly like so... <input class='text' type='text' name='org' id='org'
I have a simple html text-box hooked up to a .keypress(funcion(){...} which makes a
I have a login form, which contains simple text box, that shows the text
I want to create a simple gsp page which will have an input box

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.