title: How to print only the matched regex strings from a block of text?
body: <p>The end goal I have is to input a block of text (multiple lines) which contains domains and output just a list of domains. </p>
  
  <p>Example input:</p>
  
  <pre><code>2017-03-02:  173.254.221.115 port 80 - www.hlowdolax.top - GET /usp?f=1if
  2017-03-02:  173.254.221.115 port 80 - www.hjaoopoa.top - GET /uf=1if
  2017-03-04:  173.254.221.115 port 80 - www.foolalexas.top - GET /userif
  2017-03-04:  54.202.16.39 port 80 - pentsshoperqunity.top - 
  </code></pre>
  
  <p>The output I want in this case:</p>
  
  <pre><code>www.hlowdolax.top
  www.hjaoopoa.top
  www.foolalexas.top
  pentsshoperqunity.top
  </code></pre>
  
  <p>Eventually I found out that the best tool for this purpose is <code>re.findall()</code> and tried to do it this way:</p>
  
  <pre><code>matchedDomains=re.findall(myRegex, fileWithMessyText.read())
  print matchedDomains
  </code></pre>
  
  <p>And in the output I see that it matched all the domains but the result looks like this:</p>
  
  <pre><code>[('www', 'hlowdolax', 'to', 'p'), ('user', 'p', 'h', 'p'), ('1', 'g', 'i', 'f'), ('www', 'hjaoopoa', 'to', 'p'), ('user', 'p', 'h', 'p'), ('1', 'g', 'i', 'f'), ('www', 'foolalexas', 'to', 'p'), ('user', 'p', 'h', 'p'), ('1', 'g', 'i', 'f'), ('pentsshoperqunity', 't', 'o', 'p'), ('search', 'p', 'h', 'p'), ('nikesportweardewvv', 't', 'o', 'p'), ('search', 'p', 'h', 'p'), ('www', 'dpooldoopl', 'a', 'top'), ('user', 'p', 'h', 'p'), ('1', 'g', 'i', 'f'), ('fordfocuscommunoityesz', 't', 'o', 'p'), ('www', 'sosgenerga', 'lz', 'top'), ('user', 'p', 'h', 'p'), ('1', 'g', 'i', 'f'), ('fordfocuscommunoityesz', 't', 'o', 'p'), ('search', 'p', 'h', 'p')]
  </code></pre>
  
  <p>If that's relevant, here is the regex I use:</p>
  
  <pre><code>([A-Za-z0-9]{1,})\.([A-Za-z0-9]{1,10})\.?([A-Za-z]{1,})\.?([A-Za-z]{1,})
  </code></pre>
  
  <p>I googled a variety of keywords, tested my regex with pythex.org and learned about a term "match captures" and that it has to do something with "capture groups", but all the advice I found here with using <code>group</code> appears to not be compatible with <code>findall</code>, but if I try to use <code>search</code> or <code>match</code> it only works for the first line and prints the whole line instead of just the match (looks like rambling but I didn't document my wanderings so I don't remember what exactly I've tried). Also intuitively it seems like a workaround to use cycles and match line by line when there is a tool that matches the whole block. Problem is, I don't know how to use it.</p>
  
  <p>I'm not looking for someone to write the code for me but I'm really lost at this point. Is there a way to use <code>findall</code> and output just nicely formatted matches?</p>