Python - combine regex patterns
<p>I have a large text and the aim is to select all 10-character strings for which the first character is a letter and the last character is a digit. </p>

<p>I am a python rookie and what I managed to achieve is to find all 10-character strings:</p>

<pre><code>ten_char = re.findall(r"\D(\w{10})\D", pdfdoc)
</code></pre>

<p>Question is how can I put together my other conditions: apart from a 10-character string, I am looking for one where the first character is a letter and the last character is a digit. </p>

<p>Suggestions appreciated!</p>

<p>If I understand it, do:</p>

<pre><code>r'\b([a-zA-Z]\S{8}\d)\b'
</code></pre>

<p><a href="https://regex101.com/r/dM7lI7/2" rel="nofollow">Demo</a></p>

<p>Python demo:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; txt="""\
... Should match:
... a123456789 aA34567s89 zzzzzzzer9
... 
... Not match:
... 1123456789 aA34567s8a zzzzzzer9 zzzxzzzze99"""
&gt;&gt;&gt; re.findall(r'\b([a-zA-Z]\S{8}\d)\b', txt)
['a123456789', 'aA34567s89', 'zzzzzzzer9']
</code></pre>

python regex