When I look for a regular expression for InChI, I succeed on [EBI's MIRIAM Registery website](http://www.ebi.ac.uk/miriam/main/collections/MIR:00000383):

    ^InChI\=1S?\/[A-Za-z0-9]+(\+[0-9]+)?(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,\/]+)*$

And indeed it works for some examples:

    import re
    
    pattern = '^InChI\=1S?\/[A-Za-z0-9]+(\+[0-9]+)?(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,\/]+)*$'
    
    s = 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3'
    
    re.findall(pattern, s)  

will print 

    [('', '/c1-2-3/h3H,2H2,1H3')]

However, if I take other examples, as e.g. [this one](http://www.chemodex.com/de/products/d-mannose/)

    s2 = 'InChI=1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5+,6?/m1/s1'

it fails

    re.findall(pattern, s2)

will return

    []

What is the correct and general regular expression for InChI?

**EDIT**

If I see this correctly, in the pattern from above, question marks are not taken into account which are used to [mark both “unknown” and “undefined” chiral centres](http://www.inchi-trust.org/technical-faq/#8.6). If one adjusts the regex accordingly, it at least works for the example above; whether it then holds for all InChI is unclear, of course.

    pattern = '^InChI\=1S?\/[A-Za-z0-9]+(\+[0-9]+)?(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,\/\?]+)*$'
    
    s2 = 'InChI=1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5+,6?/m1/s1'
    
    re.findall(pattern, s2)

will return

    [('', '/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5+,6?/m1/s1')]