from extract_lines import *
        
if __name__ == "__main__":
    data = """
    static const double
    u00  = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
    u01  =  1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
    u02  = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
    u03  =  3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
    u04  = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
    u05  =  1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
    u06  = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
    v01  =  1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
    v02  =  7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
    v03  =  2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
    v04  =  4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
    """
    # Split the lines
    # Could do this instead: lines = file("data.c","r").readlines()
    lines = data.split("\n")
    
    # Extract and substitute
    newLines = extract_lines(lines, 
        r"u00", # Find first occurence of "u00"
        r";", # End on line with ";"
        # Extraction pattern:
        r".*([a-z][0-9][0-9]) += +([-+]?[0-9]+[.][0-9]+e[-+]?[0-9]+).*", # Extract floating-point numbers only
        r"\1,\2", # Keep groups 1 and 2 and separate with comma
        removeStart = False) # Keep start match since it contains u00

    # Show the result
    for line in newLines:
        print line
