title: How to replace a character at beginning and end of a string in python
body: <p>I have a string:</p>
  <pre><code>path = &quot;{'ResponseMetadata': {'Flag': 'Processed', 'Message': 'File Ingested successfully', 'INGEST_PATH': ['inward/emr_batch/manual_cars/xy99', &quot;&quot;manual_cars/xy99/2020/08/12/145938/ABC KPI's Jan 2018.csv&quot;&quot;]}}
  </code></pre>
  <p>I would like to replace ' at the beginning and end of the strings only and not in middle of strings.</p>
  <p>I am trying to make use of replace function of python to perform this task</p>
  <pre><code>path = path.replace(&quot;\'&quot;, &quot;\&quot;&quot;)
  </code></pre>
  <p>but above approach is replacing the ' every where in string and output obtained is</p>
  <pre><code>{&quot;ResponseMetadata&quot;: {&quot;Flag&quot;: &quot;Processed&quot;, &quot;Message&quot;: &quot;File Ingested successfully&quot;, &quot;INGEST_PATH&quot;: [&quot;inward/emr_batch/manual_cars/xy99&quot;, &quot;&quot;manual_cars/xy99/2020/08/12/145938/ABC KPI&quot;s Jan 2018.csv&quot;&quot;]}}
  </code></pre>
  <p>but I do not want KPI's to get change to KPI&quot;s, <strong>one way which i can achieve this is to make use of replace function again like below to gain desired output</strong>, but then problem with below approch is that I need to keep on adding replace with each new scenario and I would like to have generic solution can some one help here.</p>
  <pre><code>path = path.replace(&quot;\'&quot;, &quot;\&quot;&quot;).replace('&quot;s', &quot;'s&quot;)
  </code></pre>
  <p>Regards
  Mahi</p>