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

The Archive Base Latest Questions

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

I am using C#. NET 2.0 and WinForms. I have a piece of code

  • 0

I am using C#. NET 2.0 and WinForms.

I have a piece of code which is formatted in Assembly like this:

VARIABLE = 40
ADDRESS = $60

LDA VARIABLE;
STA ADDRESS;

Output should be:

!VARIABLE = 40
!ADDRESS = $60

LDA !VARIABLE;
STA !ADDRESS;

Of course, there is much more than that. Like 2000 lines, but the point is there are declarations at the top of the file and I can load/save or do whatever with them. But my problem is, I have to “prepend” ALL of these declarations (even in raw code) with a !.

My current method is this:

        var defs = tab.tb.GetRanges(@"^\s*([A-Za-z0-9_]+){4,255}\s*=", RegexOptions.Multiline); // all declarations are formatted like this, so use regex to get all of them
        foreach (var def in defs)
        {
            string actual = def.Text.Substring(0, def.Text.IndexOf(' ')); // remove the = sign since its not used in actual code
                txt = txt.Replace(actual, "!" + actual);
        }

However, this method is very slow. It takes approximately 3 seconds to “fix up” all of the declarations in my file. Is there any better way? And for the record, the syntax is slightly different from a normal text box because I am using http://www.codeproject.com/KB/edit/FastColoredTextBox_.aspx as my text control.

  • 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-27T19:57:49+00:00Added an answer on May 27, 2026 at 7:57 pm

    You nest quantifiers in your regex!

    ([A-Za-z0-9_]+){4,255}
    

    Take a simple string as ‘aaaaaaaa’: what is the regex engine supposed to capture? ‘a’ 8 times, ‘aa’ 4 times, ‘aa’, then ‘a’, then ‘a’, then… ?

    This is very probably the cause of your performance problems. Just don’t do that! All the more that you try to match in the whole file. Even though the regex engine will eventually choose the leftmost, longest match, it tries all possibilities, always.

    Remove the +!

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

Sidebar

Related Questions

I have an SDK in unmanaged code that I'm using in a .NET Winforms
I'm using agsXMPP in my .NET project (WinForms) I have the following Code block,
I have a C#/.NET Winforms application which has some settings stored using A '.settings'
I have a .net winforms ListBox and I've added items to it using .Add().
I am using VB.Net WinForms. I would like to call the Adobe Reader 9
I'm using a RichTextBox (.NET WinForms 3.5) and would like to override some of
Using c#, VS2005, and .NET 2.0. (XP 32 bit) This is a Winforms app
I am using .NET winforms. I have a groupBox that contains a set of
I have a .NET application that was written in C# and VB.NET using WinForms.
I have several WinForms .NET programs that are started using ClickOnce. The user logs

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.