Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Created August 11, 2011 15:26
Show Gist options
  • Select an option

  • Save BaseCase/1139936 to your computer and use it in GitHub Desktop.

Select an option

Save BaseCase/1139936 to your computer and use it in GitHub Desktop.
import re
with_style = '<div style="things and stuff" class="whatnot">hi there</div>'
without_style = re.sub(r"""style=('|")(.*)\\1""", '', with_style)
@BaseCase

Copy link
Copy Markdown
Author

So the goal is to strip out all 'style' attributes. Since you can have either ' or " as a quote in html, I'm trying to use that first group to catch which one is being used and then use the same one at the '\1', which is supposed to represent the first group that was matched. For some reason, this doesn't work...without_style is the same string as with_style.

Wha happen?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment