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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:43:49+00:00 2026-06-08T23:43:49+00:00

Let’s say I have the subject: ////////File description//////// Name: SomeFile.cs Size: 234 Description: Foo

  • 0

Let’s say I have the subject:

////////File description////////
Name: SomeFile.cs
Size: 234
Description: Foo
Date: 08.14.2012
///////////////////////////////

how can I make that subject turn into:

////////File description////////
Name: 
Size: 
Description: 
Date:
///////////////////////////////

Right now I do the following:

var pattern = 
@"(/+File description/+
Name: )(?<name>.+)(
Size: )(?<size>.+)(
Description: )(?<des>.+)(
Date: )(?<date>.+)(
/+)";

// subject = fist code at top of this questoin

var temp = Regex.Replace(subject,pattern,"$1$2$3$4$5");

The pattern is very messy



Now my question is:

I will like to have the pattern:

/+File description/+
Name: (?<name>.+)
Size: (?<size>.+)
Description: (?<des>.+)
Date: (?<date>.+)
/+

I was wondering if it is possible to replace the groups name, size. etc with nothing

  • 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-08T23:43:49+00:00Added an answer on June 8, 2026 at 11:43 pm

    This may be more complex than you would like, but you could try using the MatchEvaluator. The MatchEvaluator computes the replacement string for each match. And the MatchEvaluator has access to the “Match” object, so it can do some interesting things, limited only by your imagination…

            var pattern =
    @"/+File description/+ 
    Name: (?<name>.+) 
    Size: (?<size>.+) 
    Description: (?<des>.+) 
    Date: (?<date>.+) 
    /+";
            var temp = Regex.Replace(data, pattern, new MatchEvaluator(eval));
            Console.WriteLine("{0}", temp);
        //...
        string eval(Match mx)
        {
            Stack<Group> stk = new Stack<Group>();
            for(int i=1; i<mx.Groups.Count; ++i)
                stk.Push(mx.Groups[i]);
    
            string result = mx.Groups[0].Value;
            int offt = mx.Index;
            while(stk.Count > 0)
            {
                var g = stk.Pop();
                int index = g.Index - offt;
                result = result.Substring(0,index) + result.Substring(index+g.Length);
            }
            return result;
        }
    

    Another approach using the MatchEvaluator looks like this (and should work with your pattern or mine).

        string eval2(Match mx)
        {
            string data = mx.Value;
            data = Regex.Replace(data, "Name: .+", "Name: ");
            data = Regex.Replace(data, "Size: .+", "Size: ");
            data = Regex.Replace(data, "Description: .+", "Description: ");
            data = Regex.Replace(data, "Date: .+", "Date: ");
            return data;
        }
    

    This works because you are replacing within a Match. I.e., your outer Match narrows down the search while your individual replacements have no chance of replacing the wrong thing. If you use this approach, your outer pattern can be much simpler because the groups are not needed.

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

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say that I have a date in R and it's formatted as follows.
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have a due date and a reminder timespan . How do
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have a dataset, which can be neatly classified using weka's J48

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.