I\'m trying to get the elements in an HTML doc that contain the following pattern of text: #\\S{11}
this is cool #12345678901
<
from BeautifulSoup import BeautifulSoup
import re
html_text = """
this is cool #12345678901
this is nothing
foo #126666678901
this is interesting #126666678901
this is blah #124445678901
"""
soup = BeautifulSoup(html_text)
for elem in soup(text=re.compile(r' #\S{11}')):
print elem.parent
Prints:
this is cool #12345678901
this is interesting #126666678901
this is blah #124445678901