Python regex matching words with repeating consonant
<p>First off, this is homework. (I couldn't use a tag in the title and nothing showed up in the tag list at the bottom for homework, so please let me know if I should EDIT something else regarding this matter).</p>

<p>So I have been reading through the python docs and scavenging SO, finding several solutions that are close to what I want, but not exact.</p>

<p>I have a dictionary which I read in to a string:</p>

<pre><code>a
aa
aabbaa
...
z
</code></pre>

<p>We are practicing various regex patters on this data. 
The specific problem here is to return a list of words which match the pattern, NOT tuples with the groups within each match.</p>

<p>For example:</p>

<p>Given a subset of this dictionary like:</p>

<pre><code>someword
sommmmmeword
someworddddd
sooooomeword
</code></pre>

<p>I want to return:</p>

<pre><code>['sommmmmword', 'someworddddd']
</code></pre>

<p>NOT:</p>

<pre><code>[('sommmmword', 'mmmmm', ...), ...] # or any other variant
</code></pre>

<p>EDIT:</p>

<p>My reasoning behind the above example, is that I want to see how I can avoid making a second pass over the results. That is instead of saying:</p>

<pre><code>res = re.match(re.compile(r'pattern'), dictionary)
return [r[0] for r in res]
</code></pre>

<p>I specifically want a mechanism where I can just use:</p>

<pre><code>return re.match(re.compile(r'pattern'), dictionary)
</code></pre>

<p>I know that may sound silly, but I am doing this to really dig into regex. I mention this at the bottom.</p>

<p>This is what I have tried:</p>

<pre><code># learned about back refs
r'\b([b-z&amp;&amp;[^eiou]])\1+\b' -&gt; # nothing

# back refs were weird, I want to match something N times
r'\b[b-z&amp;&amp;[^eiou]]{2}\b' -&gt; # nothing
</code></pre>

<p>Somewhere in testing I noticed a pattern returning things like <code>'\nsomeword'</code>. I couldn't figure out what it was but if I find the pattern again I will include it here for completeness.</p>

<pre><code># Maybe the \b word markers don't work how I think?
r'.*[b-z&amp;&amp;[^eiou]]{2}' -&gt; # still nothing

# Okay lets just try to match something in between anything
r'.*[b-z&amp;&amp;[^eiou]].*' -&gt; # nope

# Since its words, maybe I should be more explicit.
r'[a-z]*[b-z&amp;&amp;[^eiou]][a-z]*' -&gt; # still nope

# Decided to go back to grouping.
r'([b-z&amp;&amp;[^eiou]])(\1)'  # I realize set difference may be the issue

# I saw someone (on SO) use set difference claiming it works
#  but I gave up on it...

# OKAY getting close
r'(([b-df-hj-np-tv-xz])(\2))' -&gt; [('ll', 'l', 'l'), ...]

# Trying the the previous ones without set difference 
r'\b(.*(?:[b-df-hj-np-tv-xz]{3}).*)\b'  -&gt; # returned everything (all words)

# Here I realize I need a non-greedy leading pattern (.* -&gt; .*?)
r'\b(.*?(?:[b-df-hj-np-tv-xz]{3}).*)\b' -&gt;  # still everything

# Maybe I need the comma in {3,} to get anything 3 or more
r'\b(.*?(?:[b-df-hj-np-tv-xz]{3,}).*)\b' -&gt;  # still everything

# okay I'll try a 1 line test just in case
r'\b(.*?([b-df-hj-np-tv-xz])(\2{3,}).*)\b'  
    # Using 'asdfdffff' -&gt; [('asdfdffff', 'f', 'fff')]
    # Using dictionary -&gt; []  # WAIT WHAT?!
</code></pre>

<p>How does this last one work? Maybe there there are no 3+ repeating consonant words? I'm using <code>/usr/share/dict/cracklib-small</code> on my schools server which is about 50,000 words I think.</p>

<p>I am still working on this but any advice would be awesome.</p>

<p>One thing I find curious is that you can not back reference a non-capturing group. If I want to output only the full word, I use (?:...) to avoid capture, but then I can not back reference. Obviously I could leave the captures, loop over the results and filter out the extra stuff, but I absolutely want to figure this out using ONLY regex!</p>

<p>Perhaps there is a way to do the non-capture, but still allow back reference? Or maybe there is an entirely different expression I haven't tested yet.</p>