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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:49:07+00:00 2026-05-24T12:49:07+00:00

s = re.sub(r<style.*?</style>, , s) Isn’t this code supposed to remove styles in the

  • 0
s = re.sub(r"<style.*?</style>", "", s)

Isn’t this code supposed to remove styles in the s string? Why does it not work? I am trying to remove the following code:

<style type="text/css">
body { ... }
</style>

Any suggestion?

  • 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-24T12:49:08+00:00Added an answer on May 24, 2026 at 12:49 pm

    No it’s the re.DOTALL flag that is necessary !

    re.DOTALL
    Make the ‘.’ special character match any character at all, including a newline; without this flag, ‘.’ will match anything except a newline.

    http://docs.python.org/library/re.html#re.DOTALL

    Edit

    In some cases, it may be necessary to have a dot matching all characters (newlines comprised) in a region of a string, and to have a dot matching only non newlines characters in another region of the sting. But using flag re.DOTALL doesn’t allow this.

    In this case, it’s usefull to know the following trick: using [\s\S] to symbolize every character

    import re
    
    s = '''alhambra
    <style type="text/css">
    body { ... }
    </style>
    toromizuXXXXXXXX
    YYYYYYYYYYYYYY'''
    print s,'\n'
    
    regx = re.compile("<style[\s\S]*?</style>|(?<=ro)mizu.+")
    
    s = regx.sub('AAA',s)
    print s
    

    result

    alhambra
    <style type="text/css">
    body { ... }
    </style>
    toromizuXXXXXXXX
    YYYYYYYYYYYYYY 
    
    alhambra
    AAA
    toroAAA
    YYYYYYYYYYYYYY
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to style my sub headings, and I have a design where the
I can access this CSS stylesheet from sub-category (folder) by: <link rel=stylesheet type=text/css href=../style.css
Can't figure out what this isn't working right. Trying to get each button_select_sub li's
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
While attempting my first sub-class in Objective-C I have come across the following warning
We have a sub-project 'commonUtils' that has many generic code-snippets used across the parent
I have a procedure that iterates through the styles available to a document: Sub
As you aware, in .NET code-behind style, we already use a lot of function

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.