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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:08:06+00:00 2026-05-13T22:08:06+00:00

i’m trying to find a way to match this problem but i’m LOST i

  • 0

i’m trying to find a way to match this problem but i’m LOST

i want it to match a math equation that will accept string if:

  • “+-*/%” at anywhere in the string but not in the last character of the input string
  • it accepts float and integers
  • it doesn’t accepts letters just numbers and signs

any help ?

Thanks in advance !!

  • 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-13T22:08:07+00:00Added an answer on May 13, 2026 at 10:08 pm

    The regular expression you’re after looks something like:

    -?\d+(?:\.\d+)?([*/%+-]-?\d+(?:\.\d+)?)+
    

    Basically this means:

    NUMBER (OPER NUMBER)*
    

    A number is defined as:

    • Optional minus sign;
    • One or more digits;
    • Optionally a period followed by one or more digits.

    Now the leading optional minus is not strictly in your requirements so you can safely drop it but without it you can’t recognize:

    -3*-4
    

    which violates your condition of two operands together. To drop it just drop -? from the expression (in both places) ie:

    \d+(?:\.\d+)?([*/%+-]\d+(?:\.\d+)?)+
    

    It’s also not clear if you want to accept many operands or just one. If it’s just one then:

    -?\d+(?:\.\d+)?[*/%+-]-?\d+(?:\.\d+)?
    

    or

    \d+(?:\.\d+)?[*/%+-]\d+(?:\.\d+)?
    

    or a variant allowing spaces (\s). You will probably also want to capture the groups using parentheses.

    You may want to alter that definition.

    Also you could consider allowing spaces between numbers and operands.

    An example of usage:

    var s = "-11.32 * -34";
    var r = /(-?\d+(?:\.\d+)?)\s*([*/%+-])\s*(-?\d+(?:\.\d+)?)/;
    var m = r.exec(s);
    if (m != null) {
      alert("First: " + m[1] + "\nOperand: " + m[2] + "\nSecond: " + m[3]);
    } else {
      alert("Not found");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post

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.