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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:48:34+00:00 2026-05-27T23:48:34+00:00

I need one string to be checked and modified many times (searching and replacing

  • 0

I need one string to be checked and modified many times (searching and replacing different seqences) but it is not working well. I guess its because of the immutability.

private string DoRegexCheck(string line)
{
  string pattern;

  foreach (string re in this.regexPatterns.Items)
  {
    pattern = re;
    Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
    line=r.Replace(line, ""); //the line should be updated and the check should continue with updated line 
  }                            

  return line;
}
  • 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-27T23:48:35+00:00Added an answer on May 27, 2026 at 11:48 pm

    “it is not working well” is somewhat ambiguous.

    If you mean “it isn’t changing line – then that code is fine. Immutability is not an issue at all, since we are changing to a new string each Replace (the code as shown does not try to edit an existing string). If it isn’t updating as expected, then your Regex patterns are simply incorrect.


    If you mean performance: you can’t change the way Regex works on strings; I would, however, suggest caching the various regex using the Compiled option, so that you have an array or dictionary of pre-compiled Regex that you re-use. This is especially important if applying this for thousands of lines.

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

Sidebar

Related Questions

I have one JSON that is coming in a string format. I need to
I need to be able to take a string like: '''foo, bar, one, two,
i need a regex to replace a string. <span class=\Translation\ lang=\ThisLanguage\> with this one:
For a one-shot operation, i need to parse the contents of an XML string
I need to check if a string is found in one or more columns.
I need to write code to determine if 2 strings match when one of
I need a regex to run against strings like the one below that will
I need to define some constant strings that will be used only by one
I need to write a Java Comparator class that compares Strings, however with one
I need one of my .exe to always run as administrator without UAC prompt.

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.