Perl - regex How to write this in python?
Question: I wrote the following `regex` in `perl` and now i want to write it in
`python`.

    
    
    if ($textline =~ /^([A-Z0-9]+:)(.*)/)
    


Answer: 
    >>> import re
    >>> textline = "AZERTY:qwerty"
    >>> if re.search('^([A-Z0-9]+:)(.*)', textline):
    ...     print("match !")
    

<http://docs.python.org/library/re.html>

If you have problems using the interactive python interpreter, copy/paste this
in your terminal :

    
    
    cd /tmp
    wget http://sputnick-area.net/ftp/downloads/re.py
    chmod +x re.py
    ./re.py
    

**Edit** : this is an example that should fit your needs :

    
    
    #!/usr/bin/python2
    # -*- coding: utf8 -*-
    
    # $ cat /tmp/dmesg
    # AZERTY:qwerty01
    # AZERTY:qwerty02
    # zzzzzzzzzzzzzzz
    # AZERTY:qwerty03
    
    import re
    
    f = open("/tmp/dmesg", "r")
    for textline in f.readlines():
        if re.search('^([A-Z0-9]+:)(.*)', textline):
            print "match "+textline.rstrip('\n')
    
    f.close()
    

