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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:26:52+00:00 2026-06-14T21:26:52+00:00

I am trying to strip the content from between the h2 tags in a

  • 0

I am trying to strip the content from between the h2 tags in a string using a Regex in C#:

<h2>content needs removing</h2> other content...

I have the following Regex, which according to the Regex buddy software I used to test it, should work, but it doesn’t:

myString = Regex.Replace(myString, @"<h[0-9]>.*</h[0-9]>", String.Empty);

I have another Regex that is run after this to remove all other HTML tags, it is called in the same way and works fine. Can anyone help me out with why this isn’t working?

  • 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-14T21:26:53+00:00Added an answer on June 14, 2026 at 9:26 pm

    try this code :

    String sourcestring = "<h2>content needs removing</h2> other content...";
    String matchpattern = @"\s?<h[0-9]>[^<]+</h[0-9]>\s?";
    String replacementpattern = @"";
    MessageBox.Show(Regex.Replace(sourcestring,matchpattern,replacementpattern));
    

    [^<]+ is more safer than .+ because it stops collecting where it sees a <.

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

Sidebar

Related Questions

I'm trying to strip some content from an HTML file automatically, and I'm using
I'm trying to strip the numeric and punctuations from a string leaving only alpha
I am trying to create a match query which selects text from a string
I have been trying to strip out some data from HTML files. I have
I'm trying to strip content titles out of the middle of text strings. Could
I am trying to get the contents from span, class, div from external other
hi all I'm trying to extract the META description from a webpage using libxml
I'm working on a very graphic-heavy application which uses content from a bunch of
I am trying to get the innerhtml of div tags in a file using
I have this html. I'm trying to get its InnerText without any tags 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.