regex to match several string in Python
<p>I have questions with regex in Python.</p>

<p>Possible variations can be </p>

<p>10 hours, 12 weeks or 7 business days.</p>

<p>I want to have my regex something like </p>

<pre><code>string = "I have an 7 business day trip and 12 weeks vacation."
re.findall(r'\d+\s(business)?\s(hours|weeks|days)', string)
</code></pre>

<p>so that I expect to find "7 business day" and "12 weeks" but it returns None</p>

<pre><code>string = "I have an 7 business day trip and 12 weeks vacation."
print re.findall(r'\d+\s(?:business\s)?(?:hour|week|day)s?', string)
['7 business day', '12 weeks']

\d+\s(?:business\s)?(?:hour|week|day)s?
</code></pre>

<p><a href="https://www.debuggex.com/r/Ytu1HFfbmsd3BpFV" rel="nofollow">Debuggex Demo</a></p>

<p>The demo should explain how this works. The reason yours wasn't is because it was looking for <code>7 businessdays</code> which doesn't match.</p>

<p>Although if you don't want to accept <code>business week/hour</code>, you'll need to modify it further:</p>

<pre><code>\d+\s(?:hour|week|(?:business )?day)s?
</code></pre>

<p><a href="https://www.debuggex.com/r/DeXvPszNWq8p7qVq" rel="nofollow">Debuggex Demo</a></p>

python regex