title: RegEx matching odd number of characters at the beginning and the end of string
body: <p>I have grammar is Lezer where I need to match a &quot;custom string&quot; which can start with any odd number of <code>&quot;</code> and end with the same corresponding number. It can span multiple lines as well and anything inside needs to be <code>skipped</code> as far as the parser is concerned. I am struggling a little with the regEx part of the matching.</p>
  <pre><code>str&quot;test&quot;      // valid
  str&quot;&quot;&quot;test&quot;&quot;&quot; // valid
  
  str&quot;&quot;test&quot;&quot;     // not valid
  str&quot;&quot;&quot;&quot;test&quot;&quot;&quot;&quot; // not valid
  </code></pre>
  <p>I am trying to match the beginning and end of that string.</p>
  <p>I tried among other things <code>&quot;(&quot;&quot;)*[^&quot;]</code> but it matches the first letter after the odd double quotes (due to the <code>[^&quot;]</code> which is something I would like to avoid.</p>
  <p>For matching the end I have a similar issue.</p>
  <p>So with the given input of:</p>
  <pre><code>1 str&quot;test&quot;
  2 str&quot;&quot;&quot;
  3 a
  4 b
  5 c
  6 &quot;&quot;&quot;
  7 str&quot;&quot;nope&quot;&quot;
  </code></pre>
  <p>I am trying to match only <code>str&quot;</code> for line 1 and <code>str&quot;&quot;&quot;</code> for line 2 and not match on line 7.</p>
  <p>Need to match the ends as well (not in the same regex). So the match should be on <code>&quot;</code> for line 1 and <code>&quot;&quot;&quot;</code> for line 6.</p>
  <p>I have this so far: <strong>start</strong>: <code>^str&quot;(&quot;&quot;)*[^&quot;]</code> <strong>end</strong>: <code>[^&quot;]&quot;(&quot;&quot;)*$</code> but it is not optimal.</p>
  <p>FYI I need start and end since the expectation is when you start writing and we hit a match on the beginning the highlighting in the editor should highlight all remaining text as a string until you have a matching odd number of <code>&quot;</code>.</p>
  <p>Any advice is appreciated.</p>