regex library c# 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)){
return true;
} else {
return false;
}
Example 2: c# regex
public static Dictionary<string, string> FindPattern(this string text, string pattern)
{
Regex expression = new Regex(pattern);
Match match = expression.Match(text);
Dictionary<string, string> matchvalue = new Dictionary<string, string>();
if (match.Success)
{
foreach (string g in expression.GetGroupNames())
{
matchvalue[g] = match.Groups[g].Value;
}
return matchvalue;
}
else
{
foreach (string g in expression.GetGroupNames())
{
matchvalue[g] = "";
}
}
return matchvalue;
}