Repository: scrapy/w3lib

Issue:
remove_tags_with_content bug
use this 
`remove_tags_with_content("""<div class="hqimg_related"><div class="to_page"><span>热点栏目</span> <s class='hotSe'>
""", ("s",))`
get result:
`<div class="hqimg_related"><div class="to_page">`
There may be some mistakes
then modified the expression. 
`tags = '|'.join([r'<%s\s+.*?</%s>|<%s\s*/>' % (tag, tag, tag) for tag in which_ones])`
finally,it's work fine


Discussion:

Patch:
diff --git a/w3lib/html.py b/w3lib/html.py
index 9990a35..55fe5e3 100644
--- a/w3lib/html.py
+++ b/w3lib/html.py
@@ -220,7 +220,7 @@ def remove_tags_with_content(text, which_ones=(), encoding=None):
 
     text = to_unicode(text, encoding)
     if which_ones:
-        tags = '|'.join([r'<%s.*?</%s>|<%s\s*/>' % (tag, tag, tag) for tag in which_ones])
+        tags = '|'.join([r'<%s\b.*?</%s>|<%s\s*/>' % (tag, tag, tag) for tag in which_ones])
         retags = re.compile(tags, re.DOTALL | re.IGNORECASE)
         text = retags.sub(u'', text)
     return text


Test patch:
diff --git a/tests/test_html.py b/tests/test_html.py
index 68133cb..6d6e8ae 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -184,6 +184,10 @@ class RemoveTagsWithContentTest(unittest.TestCase):
         # text with empty tags
         self.assertEqual(remove_tags_with_content(u'<br/>a<br />', which_ones=('br',)), u'a')
 
+    def test_tags_with_shared_prefix(self):
+        # https://github.com/scrapy/w3lib/issues/114
+        self.assertEqual(remove_tags_with_content(u'<span></span>

', which_ones=('s',)), u'<span></span>')
+
 
 class ReplaceEscapeCharsTest(unittest.TestCase):
     def test_returns_unicode(self):