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

The Archive Base Latest Questions

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

I have some doubts about what I’m doing. I try to remove pices of

  • 0

I have some doubts about what I’m doing. I try to remove pices of text like the letter “n” where it is between a “(” and a ” ” or viceversa, and many other cases. I use regex to find the pattern, but how can I delete only the letter?

I’ve used this: "[( ]" + mystring + @"[)= \-\*]"

like this:

foreach(Match mm in Regex.Matches(SourceCode, @"[( ]" + mystring + @"[)= \-\*]"))
{   
    int lng= mm.Length;
    SourceCode = SourceCode.Remove(mm.Index + 1, lng- 2);
}

The problem is that it calculates the index for the original text, and if there will be removed a “n” the index for the next match will be decalated with one and will delete from a wrong place. Really strange.

Does anybody know what it is doing that?

Or maybe do you have a better ideea?

Edit:

I can’t use replace. Let’s say I want to delete “n” where n is like “(n ” so if I use replace it will delete all those three characters wich I don want. If I use replace only for n, it will delete wrong letter like the “n” from “and” . . .

  • 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-26T23:24:13+00:00Added an answer on May 26, 2026 at 11:24 pm

    Your question is a bit hard to read, but I think what you need is a replace operation, together with lookaround assertions:

    SourceCode = Regex.Replace(SourceCode, "(?<=[( ])" + mystring + "(?=[)= *-])", "");
    

    This will replace the regex mystring with nothing, but only if it is preceded by a ( or space, and followed by ), =, *, - or space.

    If you want mystring to be interpreted as a string, not as a regex, you should use Regex.Escape(mystring) instead of mystring.

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

Sidebar

Related Questions

I have some doubts about construction and initialization order guarantees in C++. For instance,
I am very new to Quartz and I have some doubts about the jobs
I have programmed an emulator, but I have some doubts about how to organizate
I have two doubts: 1. I would like to add some client side support
I have some doubts about how to concatenate MvcHtmlString instances because of this information
I have an idea of organising a game loop. I have some doubts about
I've heard recently about the Abstract Factory Pattern and have currently some doubts on
I have some doubts about this server response stream compression on MVC. Actually im
morning I have some doubts about the the way php works. I cant find
I'm developing a site and I have some doubts about the best approach to

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.