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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:57:01+00:00 2026-05-27T17:57:01+00:00

Possible Duplicate: Strip html from strings in python RegEx match open tags except XHTML

  • 0

Possible Duplicate:
Strip html from strings in python
RegEx match open tags except XHTML self-contained tags

I have the regex pattern in my python module which removes the html tags from the given string.

It doesn’t work for this case.

Input string:

string=<li class="
      tal
    "><h3><a href="/aclk?sa=l&amp;ai=CoS4y-Wz0TrnqC8y0rAfysK2DB46PiJECzoK8_yKPwd4FCAAQAigCUL7Kz4P9_____wFg5erjg5gOoAH0m_XuA8gBAakCoqvilYNWVD6qBB1P0Dm6CNzrf62IC36fDvUIh77EpeheIRdH_YEaPw&amp;sig=AOD64_2z9xPK8vOxUCpIGTjBcc2Lg-GAeA&amp;adurl=http://www.policybazaar.com/creditcards/creditcard-india.aspx%3Futm_source%3Dgoogle%26utm_medium%3Dppc%26utm_term%3DCreditcard_delhi_only%26utm_campaign%3Dcredit_card" id="pa2">Compare <b>Credit Cards</b> | PolicyBazaar.com</a></h3>Get Best <b>Credit Card</b> For Free, Now U Have a Choice, Choose wisely!<br /><cite>www.policybazaar.com/<b>credit</b>-<b>Cards</b></cite></li>

regex pattern:

 In [64]:p = re.compile(r'<.*?>')
 In [65]:text=p.sub('',str(string))
 In [66]: text
 Out[66]: '<li class="\n          tal\n        ">Compare Credit Cards | PolicyBazaar.comGet Best Credit Card For Free, Now U Have a Choice, Choose wisely!www.policybazaar.com/credit-Cards'

The result has the <li> tag still. How it should be removed irrespective of this class name and string pattern.

  • 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-27T17:57:01+00:00Added an answer on May 27, 2026 at 5:57 pm

    In that case you should use the DOTALL functionality:

    p = re.compile(r'<.*?>',re.DOTALL)
    

    should work.

    But… you should not use regexes for HTML parsing, see this: https://stackoverflow.com/a/1732454/11621

    HTH.

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

Sidebar

Related Questions

Possible Duplicate: PHP: Strip a specific tag from HTML string? Hi All, I want
Possible Duplicate: Javascript: strip out non-numeric characters from string String matching is headache for
Possible Duplicate: How to minify php page html output? I mean strip out all
Possible Duplicate: How to minify php page html output? Any reason not to strip
Possible Duplicate: Why don't self-closing script tags work? I'm trying jquery now. When I
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: Php: remove all tags, but “a href” in a text Is there
Possible Duplicate: PHP Regular express to remove <h1> tags (and their content) I have

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.