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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:25:25+00:00 2026-05-18T07:25:25+00:00

I have a data table containing two columns (pattern and neworder) and cca 100

  • 0

I have a data table containing two columns (pattern and neworder) and cca 100 rows (all with different patterns).

What I am doing is matching an input string with pattern (grouped matches), and if match occurs I want to rearrange retrieved groups with Regex.Replace command.

The thing is that Regex does not act very friendly when being used inside a loop. Since I have to match input string against more then one pattern, and rearrange the appearance of the output string the only way for me to complete this task is to use Regex class. But that does not look like a proper solution since it significantly drops the performance.

The code looks like this

DataTable dt = this.GetPatterns();
DataRow dr;
System.Collections.IEnumerator ie = dt.Rows.GetEnumerator();
while(ie.MoveNext() && !found)
{
    dr = ((DataRow)ie.Current);
    pattern = dr["pattern"].ToString();
    neworder= dr["neworder"].ToString();

    Regex reg = new Regex(pattern, RegexOptions.IgnoreCase);
    Match match = reg.Match(input_string);

    if (match.Success)
    {
    found = true;
    output = reg.Replace(input_string, neworder);
    }

}
  • 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-18T07:25:26+00:00Added an answer on May 18, 2026 at 7:25 am

    If you use the static methods to do the matching, .NET automatically caches the compiled Regex objects for you.

    if (Regex.Match(input, pattern, options).Success)
    {
      output = Regex.Replace(input, pattern, neworder, options);
    }
    

    It only caches the 15 most recently used objects by default, so you would want to increase that by adjusting the Regex.CacheSize property.

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

Sidebar

Related Questions

I have a table containing two columns in SQL that I want to extract
I have to delete some rows from a data table. I've heard that it
I have a two-dimensional array (of Strings) which make up my data table (of
I have a datatable containing 10 columns. I want to select only two columns
I have table containing data . In every row there is a checkbox plus
I have a table containing data and one of the fields is 'class' When
I have a MyISAM table containing ~20 million rows, and need to increase the
I have data from a table in a database (string) that contain text and
Hi I have following data in the table: ID-----startDate----endDate 5549 2008-05-01 4712-12-31 5567 2008-04-17
I have a small app/site on a dev server with a data table in

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.