Python Regex Matching
Question: I am inputting a text file (Line)(all strings). I am trying to make card_type
to be true so it can enter the if statement, however, it never enters the IF
statement. The output that comes out from the print line is:

    
    
    imm48-1gb-sfp/imm48-1gb-sfp
    imm-2pac-fp3/imm-2pac-fp3
    imm5-10gb-xfp/imm5-10gb-xfp
    sfm4-12/sfm4-12
    

This is the code:

    
    
        print str(card_type)            
        if card_type == re.match(r'(.*)/(.*)',line):
           card_type = card_type.group(1)
    


Answer: [`re.match`](https://docs.python.org/2/library/re.html#re.match) will return a
[`MatchObject`](https://docs.python.org/2/library/re.html#re.MatchObject) if
there's a match or `None` if there wasn't. Following code will capture the
part before `/` character:

    
    
    import re
    
    line = 'imm48-1gb-sfp/imm48-1gb-sfp'
    match = re.match(r'(.*?)/', line)
    if match:
        card_type = match.group(1)
        print card_type
    

