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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:45+00:00 2026-06-09T12:33:45+00:00

I have string as below, string str = FX(Y + 1, -(5 * 10)

  • 0

I have string as below,

string str  =  "FX(Y + 1, -(5 * 10) + FML("Test - KB")";

I would like to replace the “-” with “-1 * “. However it should not apply to literal string. For example. FML(“Test – KB”) should NOT be changed to FML(“Test -1 * KB”).

The desired output is “FX(Y + 1, -1 * (5 * 10) + FML(“Test – KB”)”.

Is there a way to do this in regular expression?

Any advice/help is much appreciated.

  • 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-09T12:33:47+00:00Added an answer on June 9, 2026 at 12:33 pm

    It will look something like this:

    var result = Regex.Replace("FX(Y + 1, -(5 * 10) + FML(\"Test - KB\")",
                               "(?<=^([^\"]|\"[^\"]*\")*)-",
                               "-1 * ");
    

    Regex explanation:

    (?<=        # preceded by..
    ^           # the start of the string, then
    ([^"]       # either not a " character
    |"[^"]*"    # or a string: "..."
    )*          # as many times as you want
    )
    -           # then match the hyphen
    

    Output for your example string is:

    FX(Y + 1, -1 * (5 * 10) + FML("Test - KB")
    

    (Note that this doesn’t handle string escapes, if they are supported in your target language.)

    This solution will handle strings properly, not just with a heuristic. Here is an example:

    FX(Y+1, -(X+Y) + "EMBEDDED: FX(Y + 1, -(5 * 10)" - (X+Y)
    

    Becomes:

    FX(Y+1, -1 *(X+Y) + "EMBEDDED: FX(Y + 1, -(5 * 10)" -1 * (X+Y)
    

    Note that the string is not touched even though it “looks like” the other parts.

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

Sidebar

Related Questions

I have an alphanumeric string like below, $string_1 = a4nas60dj71wiena15sdl1131kg12b and would like to
I will have a string like below var str = -#A This text belongs
I have a string like below string str = ABE,1A2B3CD,1B2A3C,1A2BC3E; How can i split
I have a string like this as below var str = '101,1245###company1-|102,1221###company2-|102,1651###company3-|-'; Can we
I have below string String str=select * from m_menus; select * from m_roles; I
i have a string like below $string = ' florida' how can i remove
I have a string as below: $str = /dir1/dir2/dir3/file.txt I want to remove the
I have a String like below: <script language=JavaScript type=text/javascript src=http://dns.net/adj/myhost.com/index;size=5x10;zipc=12345;myzon=north_west;|en;tile=10;ord=7jkllk456?></script> I want to access
I have the below Problem Statement PS: Given a string str and a Non-Empty
How do I replace a string in a long string like below using regex

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.