Regex to parse out a part of URL using python
<p>I am having data as follows,</p>

<pre><code>data['url']
http://hostname.com/aaa/uploads/2013/11/a-b-c-d.jpg https://www.aaa.com/
http://hostname.com/bbb/uploads/2013/11/e-f-g-h.gif https://www.aaa.com/
http://hostname.com/ccc/uploads/2013/11/e-f-g-h.png http://hostname.com/ccc/uploads/2013/11/a-a-a-a.html 
http://hostname.com/ddd/uploads/2013/11/w-e-r-t.ico
http://hostname.com/ddd/uploads/2013/11/r-t-y-u.aspx https://www.aaa.com/
http://hostname.com/bbb/uploads/2013/11/t-r-w-q.jpeg https://www.aaa.com/
</code></pre>

<p>I want to find out the formats such as .jpg, .gif, .png, .ico, .aspx, .html, .jpeg and parse it out backwards until it finds a "/". Also I want to check for several occurance all through the string. My output should be,</p>

<pre><code>data['parsed']
a-b-c-d
e-f-g-h
e-f-g-h a-a-a-a
w-e-r-t
r-t-y-u
t-r-w-q
</code></pre>

<p>I am thinking instead of writing individual commands for each of the formats, is there a way to write everything under a single command.</p>

<p>Can anybody help me in writing for theses commands? I am new to regex and any help would be appreciated.</p>

<p>This pattern returns the file names. I have just used one of your urls to demonstrate, for more, you could simply append the matches to a list of results:</p>

<pre><code>import re
url = "http://hostname.com/ccc/uploads/2013/11/e-f-g-h.png http://hostname.com/ccc/uploads/2013/11/a-a-a-a.html" 

p = r'((?:[a-z]-){3}[a-z]).'
matches = re.findall(p, url)

&gt;&gt;&gt; print('\n'.join(matches))
e-f-g-h
a-a-a-a
</code></pre>

<p>There is the assumption that the urls all have the general form you provided.</p>

python regex python-2.7 python-3.x regex-negation