How to find URL containing one word AND another using re in Python?
Question: Say I have two types of links in a html file. I want to filter out all links
with type 1. How would I do it in Python using the `re` module?

Type 1:

    
    
    http://www.domain.com/firstlevel/02-02-13/secondlevel-slug.html
    

Type 2:

    
    
    http://www.domain.com/levelone/02-02-13/secondlevel-slug.html
    

I want to find all links that contain both `firstlevel` AND `secondlevel`.

This is how I tried it:

    
    
    import re
    text = "here goes the code with various links of type 1 and type 2…"
    findURL = re.findall('.*firstlevel.*secondlevel.*',text)
    

Here is what I thought the regex means:

    
    
    find all strings that has ONE OR MORE occurances of ANY CHARACTER 
    followed by the word firstlevel 
    followed by ONE OR MORE occurances of ANY CHARACTER
    followed by the word secondlevel 
    followed by ONE OR MORE occurances of ANY CHARACTER
    

However I get an empty list as result.

What do I do wrong?


Answer: You must determine start and end of link. I.e.

    
    
    findURL = re.findall('http:.*firstlevel.*secondlevel.*\.html', text)
    

