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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:33+00:00 2026-05-23T12:09:33+00:00

Since this is my first question here on stackoverflow I hope my question is

  • 0

Since this is my first question here on stackoverflow I hope my question is correctly asked.

Basicly I have a normal .txt file which contains any text like:

car accident
people died
cat without owner


<!-- Text added at 6/29/2011 9:20:38 AM -->

Some addintional Text
other Text added
add Text

I have a write/append function which allows the user to append some text and set a little timestamp.

So my problem is: With another function, you can search and replace text in the textfile, but as you can guess if someone wants to replace the word “Text” it will be replaced in the xml-stylish comment(timestamp) as well.

My result until now is

content = Regex.Replace(content,"[^<+.*"+input+".*>+]*", replace);
//content = content of the .txt file, input = search term, replace = string to replace

But this fails miserably, as some regex pro’s will see without executing it.

Now I hope that some regex pro could help me out here and provide me a search pattern which replaces the normal text but ignores the timestamp.

I’m not realy aware of the logic from regex until now, nevertheless I understand the single expressions so this would be a hook for me to understand Regex more properly.

Thanks in advice.

  • 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-23T12:09:34+00:00Added an answer on May 23, 2026 at 12:09 pm

    If I understand your question correctly, you want to replace every instance of “Text” except for the one(s) inside the comment.

    The easist way is to use a negative lookbehind (fantastic description here) as below:

    content = Regex.Replace(content, @"(?<!<!--.*?)" + input, replace);
    

    What you’re doing is attempting to replace a repetition of any length of a character that is NOT <+.*> or a character contained in input with the value in replace.

    If you’re going to be working a lot with Regex, I would HIGHLY recommend giving the website above a good read. It’s hands down the best intro to Regex that I’ve found, the time spent now will save you lots of headaches later!

    Edit

    Updated to add flexibility thanks to @stema

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

Sidebar

Related Questions

Hey stackoverflow - This is my first question here. I have 2 tables in
Greetings everyone. This is my first question here at stackoverflow so please bear with
this is my first question to stackoverflow so here it goes... I use cruise
I have this syntax which works (since it's from the API, pretty much) <%
I am going to ask you this question here since I cannot find answer
this is my first question here at Stack Overflow. I've been looking for a
I have seen this post here (http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state). I am having a similar problem I
Ok, I've run across my first StackOverflowError since joining this site, I figured this
Been a while since I've dealt with ASP.NET and this is the first time
OK I'm redoing this since I messed it up. :) here's the xaml. <Window

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.