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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:04+00:00 2026-06-17T10:33:04+00:00

I’m sure this question has been asked somewhere (maybe on here), but I couldn’t

  • 0

I’m sure this question has been asked somewhere (maybe on here), but I couldn’t find any information and that may be due to the fact that I’m not sure how to describe it exactly.

Essentially, I’m looking do an advanced find and replace. The replace I’m sure I can figure out when it comes to it, but right now I can’t get the find to work.

In an application, there are a lot of htm files being loaded. The user chooses a file and performs an action with it. After this action is done, I want the system to scan the file one more time to ensure there aren’t issues. For example, this string could be present in the htm file:

<?strange_tag_start 
     name="var_value" ?>Name<?strange_tag_end ?>

And, yes, it could be broken across lines like this. The above isn’t a problem unless this happens:

<?strange_tag_start 
     name="var_value" ?><?strange_tag_start 
     name="var_value" ?>Name<?strange_tag_end ?><?strange_tag_end ?>

The line breaks could be different. What I want to do is search the document for strings that contain <?strange_tag then contain <?strange_tag_end ?>. After if it find those, I want to check within the string whether there is either another <?strange_tag_start or another <?strange_tag_end ?>.

I initially tried reading the file and getting every index of the specific values then attempting to compare them. However, the following could be present in the file, and these are perfectly ok, but the system finds them and flags them for me:

<?strange_tag_start 
     name="var_value" ?>Name<?strange_tag_end ?> There is other text here
and some more text on another line. Then this <?strange_tag_start name="var_value"
             ?>Name<?strange_tag_end ?> is present.

What it boils down to is a system (such as is present in some applications) where the beginning of a string is specified, the end of the string is specified, and then the system checks to see if it contains a string.

If this doesn’t make sense or you need more clarification, I can do that.

UPDATE

Let me clarify with this. I have the following multiline string:

I want to preserve<?start_foo  
                bar="value" ?> the content  
<?start_baz qux="value" ?>Name  
<?end-baz_qux ?>that is between weird tags.

I want to find <?start_foo bar="value"
I also want to find <?end-baz_qux ?> (Note: There could be two of these right next to each other.)
After finding those, I want to check if inside that string is another <?start_foo bar= (Note: The “value” in that tag could be different as well.)
Then I want to remove the middle content that is not suppose to be there so I end up with:

I want to preserve<?start_foo  
                bar="value" ?> the content 
<?end-baz_qux ?>that is between weird tags.

Here’s another example to hopefully make it clearer:

Back <?rh-udv_start name="ctrl_btn" ?><?rh-udv_start name="ctrl_btn" 
    ?>button<?rh-udv_end ?><?rh-udv_end ?> to

After doing the search, I should end up with this:

Back <?rh-udv_start name="ctrl_btn" ?>button<?rh-udv_end ?> to

Essentially, I’m looking for a way to say:

  1. Find a string that “begins” (misleading as the “begin” could be in the middle of the string) with VALUE_X.
  2. If found, find VALUE_Y after it (this should always be found if there is a VALUE_X).
  3. Check after the VALUE_Y to see if there is another VALUE_Y.
  4. Check inside the string of VALUE_X through VALUE_Y to see if contains another VALUE_X.
  5. If there is another VALUE_X, delete it. If there is a VALUE_Y immediately after VALUE_Y, delete the second VALUE_Y.
  • 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-17T10:33:05+00:00Added an answer on June 17, 2026 at 10:33 am

    I believe that

    <\?.*?\?>
    

    Would work to find the tags in most regex flavors (including Visual Studio’s – not sure which you are using).

    If you also want to replace the content between the strange tags, then could you please show us a more realistic example? It’s vital to know exactly what you are trying to match (or some very close approximation) in order to provide the correct regex. For example

    <?start_strange_tag blah="foo"?>Name<?end_strange_tag?>
    

    is very different from

    <?foo bar="baz"?>Name<?/foo?>
    

    which is different from

    <?start_foo bar="baz"?>Name<?foo_end?>
    

    Etc.

    UPDATE

    Based on your comment below, I’m going to assume that you have a document that looks like this:

    I want to preserve<?start_foo  
                        bar=\"value\" ?> the content  
    <?start_baz qux=\"value\" ?>Name  
    <?end-baz_qux ?>that is not between weird tags.
    

    And that you want the result to be:

    I want to preserve the content  
    that is not between weird tags.
    

    I will also assume that you are using the .NET regex assembly (rather than the regex that is built-in to Visual Studio. Yes, they are different.)

    If that’s the case, then you can use something like this:

    static void Main( string[] args )
    {
    
        string l_input =
            "I want to preserve<?start_foo \n" + 
            "                    bar=\"value\" ?> the content\n" +
            "<?start_baz qux=\"value\" ?>Name\n" +
            "<?end-baz_qux ?>that is not between weird tags.";
    
        string[] l_singleTags = { "foo" };
        string[] l_multiTags = { "baz" };
    
        // Removing the single tags is easy:
    
        foreach ( var l_singleTag in l_singleTags )
            l_input = Regex.Replace( l_input, @"<\?start_" + Regex.Escape( l_singleTag ) + @"\b.*?\?>", "", RegexOptions.Singleline );
    
        // Removing the multi tags is not too bad:
    
        foreach ( var l_multiTag in l_multiTags )
            l_input = Regex.Replace( l_input, @"<\?start_" + Regex.Escape( l_multiTag ) + @" (?<param>\w+).*?\?>.*?<\?end-" + Regex.Escape( l_multiTag ) + @"_\k<param>.*?\?>", "", RegexOptions.Singleline );
    
        Console.WriteLine( l_input );
    
        Console.ReadKey( true );
    
    }
    

    l_input becomes:

    I want to preserve the content  
    that is not between weird tags.
    

    UPDATE 2

    In response to your question update, try this code:

    static void Main( string[] args )
    {
    
        string l_input =
            "Back <?rh-udv_start name=\"ctrl_btn\" ?><?rh-udv_start name=\"ctrl_btn\"" +
            "   ?>button<?rh-udv_end ?><?rh-udv_end ?> to";
    
        l_input = Regex.Replace( l_input, @"<\?(?<tagname>[-a-z]+_[a-z]+).*?\?>(?=<\?\k<tagname>)", "", RegexOptions.Singleline );
    
        Console.WriteLine( l_input );
    
        Console.ReadKey( true );
    
    }
    

    l_input becomes:

    Back <?rh-udv_start name="ctrl_btn"   ?>button<?rh-udv_end ?> to
    

    It simply looks for a repeating tag and deletes it. For example:

    <?a_start foo="bar"?><?a_start    foo="bar"
    ?>
    

    the first tag will be deleted, leaving only:

    <?a_start    foo="bar"
    ?>
    

    Likewise with the end tags. The code will not tolerate space or content between tags (it will not delete either tag in that case). Feel free to work with the example until you have what you want.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.