title: Remove diacritics, except for certain diacritics on certain letters
body: <p>I'm trying to remove Hebrew diacritics. I need to remove all diacritics, except for given diacritics, coming after given letters. </p>
  
  <p>This is my non-working <code>RemoveDiacritics</code> (see <a href="https://dotnetfiddle.net/mUO6Wk" rel="nofollow noreferrer">fiddle</a>):</p>
  
  <pre><code>public static string RemoveDiacritics(Dictionary&lt;char, char[]&gt; exclude, string source)
  {
      // Exclude letters (using a lookbehind), include diacritics
      string match = "(?&lt;=[א-ת])[\u05b0-\u05c2]";    
  
      // Prepare the exclusion group
      string exclusionGroup = string.Join("|", exclude.Select(p =&gt; 
           string.Concat(p.Key, string.Join(string.Empty, p.Value)))
      );
  
      // Create the exclusion group (using a lookahead)
      string except = $"(?!{exclusionGroup})";
  
      // Do the match
      return Regex.Replace(source, string.Concat(except, match), string.Empty);
  }
  </code></pre>
  
  <p>I tested it with:</p>
  
  <pre><code>static void Main(string[] args)
  {
      string source = "חָזִיתִי כְּמִבַּעַד לֶעָשָׁן בְּקִמּוּרֵי הָרֶסֶס הַלָּבָן";
      Dictionary&lt;char, char[]&gt; exclude = new Dictionary&lt;char, char[]&gt;
      {
          {'\u05db', new char[] {'\u05bc' } }, // כּ
          {'\u05d1', new char[] {'\u05bc', '\u05b7' } }, // בַּ
      };
      string replaced = RemoveDiacritics(exclude, source);
  }
  </code></pre>
  
  <p>Expected result: <code>"חזיתי כּמבַּעד לעשן בקמורי הרסס הלבן"</code> (only 2 letters on the 2nd word should have diacritics).</p>
  
  <p>Actual result: <code>"חזיתי כְמִבַעד לעשָן בְקמורי הרסס הלָבן"</code></p>
  
  <p>In my actual result, you can see that:</p>
  
  <ol>
  <li><p>Any letter that had <code>'\u05bc'</code> (it's that little dot <em>inside</em> a letter) together with an additional diacritic, is wrongly left with that additional diacritic. </p></li>
  <li><p>Also, there are diacritics left on <code>מִ</code> and <code>שָ</code> (they are on the 2nd &amp; 3rd word, respectively). No clue why. </p></li>
  </ol>
  
  <p>How can I make it work?</p>