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>I wouldn't use regex for this. Regular string manipulation is more clear in my opinion (though I haven't tested the following code).</p>

<pre><code>def get_useful_words(filename):
    with open(filename, 'r') as file:
        for line in file:
            for word in line.split():
                if len(word) == 10 and word[0].isalpha() and word[-1].isdigit():
                    yield word


for useful_word in get_useful_words('tmp.txt'):
    print(useful_word)
</code></pre>

python regex