title: How to replace only the contents within brackets using regular expressions?
body: <p>How to replace only the contents within brackets using regular expressions?</p>
  
  <pre><code>String = "This is my string [123]"
  </code></pre>
  
  <p>I want to replace 123 with 456</p>
  
  <pre><code>Desired_String = "This is my string [456]"
  </code></pre>
  
  <p>My attempt: </p>
  
  <pre><code>regex = '.*\[(.*?)\].*'
  re.sub(regex,'456',String)
  &gt;&gt; 456
  </code></pre>
  
  <p>I'm not sure what regex to use so that it replaces the 123 with 456. </p>