title: Matching String Wrapped In Symbol For Regex Replace
body: <p>I'm trying to figure out how to implement Regex on my WordPress blog.</p>
  <p><strong>The Problem</strong></p>
  <p>I'd like to replace certain content with some inline styles, and I'm using Regex to accomplish this.</p>
  <p>My idea is as follows: find the string wrapped in a particular symbol, i.e. &quot;~string~&quot; and dynamically replace this with a span that has a particular class.</p>
  <p>I'm going for a similar effect to SO's inline <code>code</code> highlighting feature, but instead of using backticks, I'm using &quot;~&quot; as my symbol of choice (since WordPress already identifies &quot;`&quot; as code).</p>
  <p><strong>Quick Example</strong></p>
  <p><em>Original Text</em></p>
  <p><code>This is a demo paragraph with a wrapped string ~here~, with another string ~~here~~. </code></p>
  <p><em>After Regex Replacement</em></p>
  <p><code>This is a demo paragraph with a wrapped string &lt;span class=&quot;classOne&quot;&gt;here&lt;/span&gt;, with another string &lt;span class=&quot;classTwo&quot;&gt;here&lt;/span&gt;.</code></p>
  <p><strong>What I'm Struggling With</strong></p>
  <p>The regex I'm using is this: /~(.*?)~/, and it's working fine for finding strings such as &quot;~demo~&quot;, but I'm not sure how to extend it to be able to find strings with multiple delimiters, like: &quot;~~demo~~&quot;.</p>
  <p>The tricky part for me is that it needs to distinguish between just one &quot;~&quot; versus two of them because I'd like to assign different replacements to each result.</p>
  <p>Any help would be appreciated! Thanks in advance.</p>