title: Use RegEx to uppercase and lowercase the string
body: <p>I am trying to convert a string to uppercase and lowercase based on the index.</p>
  
  <p>My string is a <code>LanguageCode</code> like <code>cc-CC</code> where <code>cc</code> is the language code and <code>CC</code> is the country code. The user can enter in any format like "cC-Cc". I am using the regular expression to match whether the data is in the format <code>cc-CC</code>.</p>
  
  <pre><code>var regex = new Regex("^[a-z]{2}-[A-Z]{2}$", RegexOptions.IgnoreCase); 
  //I can use CultureInfos from .net framework and compare it's valid or not. 
  //But the requirement is it should allow invalid language codes also as long 
  //The enterd code is cc-CC format
  </code></pre>
  
  <p>Now when the user enters something <code>cC-Cc</code> I'm trying to <code>lowercase</code> the first two characters and then <code>uppercase</code> last two characters.</p>
  
  <p>I can split the string using <code>-</code> and then concatenate them.</p>
  
  <pre><code>var languageDetails = languageCode.Split('-');
  var languageCodeUpdated = $"{languageDetails[0].ToLowerInvariant()}-{languageDetails[1].ToUpperInvariant()}";
  </code></pre>
  
  <p>I thought can I avoid multiple strings creation and use <code>RegEx</code> itself to uppercase and lowercase accordingly.</p>
  
  <p>While searching for the same I found some solutions to use <code>\L</code> and <code>\U</code> but I am not able to use them as the <code>C#</code> compiler showing error. Also, <code>RegEx.Replace()</code> has a parameter or delegate  <code>MatchEvaluator</code> which I'm not able to understand.</p>
  
  <p>Is there any way in <code>C#</code> we can use <code>RegEx</code> to replace uppercase with lowercase and vice versa.</p>