title: python re regex matching in string with multiple () parenthesis
body: <p>I have this string</p>
  <pre><code>cmd = &quot;show run IP(k1) new Y(y1) add IP(dev.maintserial):Y(dev.maintkeys)&quot;
  </code></pre>
  <p>What is a regex to first match exactly <code>&quot;IP(dev.maintserial):Y(dev.maintkeys)&quot;</code></p>
  <p>There might be a different path inside the parenthesis, like (name.dev.serial), so it is not like there will always be one dot there.</p>
  <p>I though of something like this:
  <code>re.search('(IP\(.*?\):Y\(.*?\))', cmd)</code> but this will also match the single IP(k1) and Y(y1</p>
  <p>My usage will be:</p>
  <pre><code>If &quot;IP(*):Y(*)&quot; in cmd:
   do substitution of IP(dev.maintserial):Y(dev.maintkeys) to Y(dev.maintkeys.IP(dev.maintserial))
  </code></pre>
  <p>How can I then do the above substitution? In the if condition I want to do this change in order: <code>from IP(path_to_IP_key):Y(path_to_Y_key) to Y(path_to_Y_key.IP(path_to_IP_key))</code> , so IP is inside Y at the end after the dot.</p>