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

  • Home
  • SEARCH
  • 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 47877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:11:30+00:00 2026-05-10T16:11:30+00:00

I have the following string and I would like to remove <bpt *>*</bpt> and

  • 0

I have the following string and I would like to remove <bpt *>*</bpt> and <ept *>*</ept> (notice the additional tag content inside them that also needs to be removed) without using a XML parser (overhead too large for tiny strings).

The big <bpt i='1' x='1' type='bold'><b></bpt>black<ept i='1'></b></ept> <bpt i='2' x='2' type='ulined'><u></bpt>cat<ept i='2'></u></ept> sleeps. 

Any regex in VB.NET or C# will do.

  • 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. 2026-05-10T16:11:30+00:00Added an answer on May 10, 2026 at 4:11 pm

    If you just want to remove all the tags from the string, use this (C#):

    try {     yourstring = Regex.Replace(yourstring, '(<[be]pt[^>]+>.+?</[be]pt>)', ''); } catch (ArgumentException ex) {     // Syntax error in the regular expression } 

    EDIT:

    I decided to add on to my solution with a better option. The previous option would not work if there were embedded tags. This new solution should strip all <**pt*> tags, embedded or not. In addition, this solution uses a back reference to the original [be] match so that the exact matching end tag is found. This solution also creates a reusable Regex object for improved performance so that each iteration does not have to recompile the Regex:

    bool FoundMatch = false;  try {     Regex regex = new Regex(@'<([be])pt[^>]+>.+?</\1pt>');     while(regex.IsMatch(yourstring) ) {         yourstring = regex.Replace(yourstring, '');     } } catch (ArgumentException ex) {     // Syntax error in the regular expression } 

    ADDITIONAL NOTES:

    In the comments a user expressed worry that the ‘.’ pattern matcher would be cpu intensive. While this is true in the case of a standalone greedy ‘.’, the use of the non-greedy character ‘?’ causes the regex engine to only look ahead until it finds the first match of the next character in the pattern versus a greedy ‘.’ which requires the engine to look ahead all the way to the end of the string. I use RegexBuddy as a regex development tool, and it includes a debugger which lets you see the relative performance of different regex patterns. It also auto comments your regexes if desired, so I decided to include those comments here to explain the regex used above:

        // <([be])pt[^>]+>.+?</\1pt> //  // Match the character '<' literally «<» // Match the regular expression below and capture its match into backreference number 1 «([be])» //    Match a single character present in the list 'be' «[be]» // Match the characters 'pt' literally «pt» // Match any character that is not a '>' «[^>]+» //    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» // Match the character '>' literally «>» // Match any single character that is not a line break character «.+?» //    Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?» // Match the characters '</' literally «</» // Match the same text as most recently matched by backreference number 1 «\1» // Match the characters 'pt>' literally «pt>» 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Something like: find . -name '*.jar' | while read jarfile;… May 11, 2026 at 2:58 pm
  • added an answer Try converting and rounding before you compare them: $storedTotal =… May 11, 2026 at 2:58 pm
  • added an answer In your .vimrc, add this: set number nnoremap <F2> :set… May 11, 2026 at 2:58 pm

Related Questions

I have a C# application that scans a directory and gathers some information. I
I have a simple extension method on the int type so I can do
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
Using HQL, I would like to search for the starting index of sequenced objects.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.