c# regex with % string code example

Example 1: regex in c#

string regex = @"\me\";
steing testRegex = "Hit me with that titan Boa baby.";

Regex re = new Regex(regex);


if (re.IsMatch(testRegex)){
 // WIll return true if it matches. # It does
  return true;
} else {
 // Will return false if it does not macth 
  return false;
  
}

Example 2: c# regex get matched string

Regex filter = new Regex(@"(\d+)");

foreach (var item in checkedListBox1.CheckedItems)
{
    var match = filter.Match(item.ToString());
    if (match.Success)
    {
        MessageBox.Show(match.Value);
    }    
}