 <p>Make the dictionary value(s) compiled <code>re</code> that can match your string:</p> <pre><code>import re productline = '8.H.5' pattern = re.compile(r'tata.xnl.\d\.\d-dev.1.0') pl_component_dict = {'8.H.5': pattern} component_branch = "tata.xnl.1.0-dev.1.0" if pl_component_dict[productline].match(component_branch): print "PASS" else: print "ERROR:Gerrit on incorrect component" </code></pre>