Wednesday, August 14, 2019

Regex.IsMatch & Regex.Matches- get the Matched words - Matches

Regex.IsMatch   - it will return true or false.

&  Regex.Matches -  get the Matched words - Matches


var filterWords = GetTermsFromSPlist(log, secureUsrPwd);
                    try
                    {
                        string profanePattern = "";
                        bool isFirst = true;
                        filterWords.ToList().ForEach(i =>
                        {
                            if (isFirst)
                            {
                                profanePattern = "\\b" + i + "\\b";
                                isFirst = false;
                            }
                            else
                                profanePattern += "|\\b" + i + "\\b";
                        });
                        //Write Regex method
                        IsBlockedProfanity = Regex.IsMatch(htmltotext, profanePattern, RegexOptions.IgnoreCase);




                       
                        if (IsBlockedProfanity)
                        {
                            var matches = Regex.Matches(htmltotext, profanePattern, RegexOptions.IgnoreCase);
                            string flaggedTermsString1 = string.Empty;
                            if (matches.Count > 0)
                            {
                                foreach (var bWord in matches)
                                {
                                    flaggedTermsString1 += $"{bWord},";
                                }
                            }
}

No comments:

Post a Comment

Building Secure Azure AI Foundry Agents with Managed Identity

  The credential problem nobody wants to own Every team that connects an Azure AI Foundry agent to Microsoft Graph, SharePoint, Outlook, or...