title: PowerShell regex for encoding API filter into a URL
body: <p>I have a string that needs to be encoded for a URL, so I have to replace some instances of certain characters.</p>
  <p>For example:</p>
  <pre><code>filter=prop1:&quot;folder1/folder2&quot;,prop2&gt;:&quot;string &amp; string&quot;,prop3~&quot;d:d&quot;
  </code></pre>
  <p>In this example, &quot;filter=&quot; and each property name and operator (&quot;prop1:&quot;, &quot;prop2&gt;:&quot;, and &quot;prop3~&quot;) need to stay. The forward slash, ampersand, space, and the last colon (in d:d) need to be replaced with %2F, %26, %20 and %3A</p>
  <pre><code>filter=prop1:&quot;folder1%2Ffolder2&quot;,prop2&gt;:&quot;string%20%26%20string&quot;,prop3~&quot;d%3Ad&quot;
  </code></pre>
  <p>With this application, the properties and values can be separated by:</p>
  <pre><code>&gt;:
  &lt;:
  &gt;
  &lt;
  !:
  :
  ~
  !~
  </code></pre>
  <p>The characters I want to replace in each pair's &quot;value&quot; section:</p>
  <pre><code>&amp;
  $
  +
  ,
  /
  :
  ;
  =
  ?
  @
  space
  &quot;
  &lt;
  &gt;
  #
  %
  {
  }
  |
  \
  ^
  ~
  [
  ]
  </code></pre>
  <p>What is the most efficient way to do this?</p>