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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:31:51+00:00 2026-05-27T14:31:51+00:00

I need a regex expression to split math expression, like: -1*x+2*y to the: -1*x

  • 0

I need a regex expression to split math expression, like:

-1*x+2*y

to the: -1*x and 2*y

I can’t just split that string basing in the + and - (because there can be negative numbers)

  • 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-27T14:31:52+00:00Added an answer on May 27, 2026 at 2:31 pm

    You can split on + or - which is preceded by a letter, digit and potentially other elements that are acceptable in your expressions (parenthesis for example). You can use look-behind to accomplish this.

    For example in python you can do it like this:

    >>> import re
    >>> re.split('(?<=[a-zA-Z0-9)])[+-]', '-a+10*x-2*y+(-2)-b')
    ['-a', '10*x', '2*y', '(-2)', 'b']
    

    This splits on every + or - not preceded by a small or capital letter or a digit or a closing parenthesis. You may need to tweak this depending on your exact specification of what constitutes a “math expression”.

    This or similar regular expression should work in other regexp engines.

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

Sidebar

Related Questions

I need a Regular expression that allows me to split the following string in
I need a Regex Statement (run in c#) that will take a string containing
I need a regex for four-digit numbers separated by comma (default can also be
This is probably simple, but I can't figure this out: I need regex expression
I need a regex that will parse a csv-style file, something like 57 fields
I need to split a string like the one below, based on space as
I am in need of a regular expression that I can use to examine
I'm a regex newbie and need a single expression that: matches the an and
This sounds simple but my regex knowledge is limited. I need an expression to
I need a Regex that will match a java method declaration. I have come

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.