def match_or_none(string, rx):
    """
    Tries to match a regular expression and returns an integer if it can.
    Otherwise, returns None.

    @param string: String to match against
    @type  string: basestring
    
    @param rx: compiled regular expression

    @return: number or None
    @rtype: int/long or None
    """
    if string is None:
        return None
    match = rx.search(string)
    if match:
        return int(match.groups()[0])
    return None