How to pass a param to re.compile() string in beautifulsoup?
<p>I'm learning beautifulsoup, and i'd like to use the regular expression to filter string.</p>

<p>For example, the html tag is:</p>

<pre><code>&lt;div&gt;apple&lt;\div&gt;
&lt;div&gt;android&lt;\div&gt;
&lt;div&gt;windows&lt;\div&gt;
</code></pre>

<p>This code will be work:</p>

<pre><code>re_words = re.compile(u".*(apple|android).*")

for content in body.findAll("div"):
    if re_words.match(content.text):
        print content.text
</code></pre>

<p>But i'd like to dynamically add keywords in regular expression, so i try to write this code:</p>

<pre><code>word0 = "apple"
word1 = "android"

regular = "u""\".*("

regular += word0
regular += "|"
regular += word1

regular +=").*\""

re_words = re.compile(regular)

for content in body.findAll("div"):
    if re_words.match(content.text):
        print content.text
</code></pre>

<p>i failed to create a legal re.compile() this time. So someone would help?</p>