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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:26:12+00:00 2026-05-23T11:26:12+00:00

One last Regex problem I need help with. What I am trying to do

  • 0

One last Regex problem I need help with. What I am trying to do is be able to parse a math expression, while still having my Regex recognize unary symbols. I am using the following to parse an integer:

[\+\-]?[0-9]+

Which works fine in these 2 scenarios:

myVar = -5
myVar = +5

Regex correctly identifies both -5 and +5 as integers. My problem is if I have a scenario like this:

myVar = 7-5

This, however, gets matched correctly:

myVar = 7*-5

Now what Regex is doing in the 7-5 scenario is its identifying 2 integers, 7 and -5. In reality, what I want is for it to be able to identify an integer (7), a minus sign (-) and then another integer (5). What Regex pattern do I need to do this?

Thanks in advance. This is .NET Regex, by the way.

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

    Regex isn’t the best choice for parsing math expressions. Look at Recursive descent parser or Reverse Polish notation or other more appropriate algorithm.

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

Sidebar

Related Questions

I need to extract URPlus1_S2_3 from the string: Last one: http://abc.imp/Basic2#URPlus1_S2_3, using regular expression
Unfortunately, despite having tried to learn regex at least one time a year for
I am trying to get a regex expression to match a specific url format.
i'm trying to use boost regex within my program the problem is i get
I am trying to validate a password string with javascript and need some help
I have problem need to solved with Regex If i am using Firefox or
I did some timing tests and also read some articles like this one (last
I'm nearly done with a trackback system for my website, but have one last
Now with all the WaitOne and ManualResetEvent stuff working (thanks!) I've got one last
As a follow up question to my last one , is there any simple

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.