using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern =@"(?<=^|\.)[^.]*?(? =\bshall incure to all bank of amrerica Affiliates\b).*(\.|$)" string input = "anita singh is good girl.Supplier expressly acknowledges and agrees that the rights and obligations of Bank of india set forth in this Agreement shall inure to all Bank of india Affiliates.anita is a good girl." ; Match match = Regex.Match(input, pattern); if (match.Success) { Console.WriteLine("Match: " + match.Value); } } }
public static bool ExactMatch(string input, string match) { return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match))); }
var regex = new Regex(@".*your text goes here.*"); var text = "This is a Test 2. This is the sentence with 'your text goes here' xyz. The middle sentence is the one we want."; var texts = text.Split('.'); foreach(var t in texts) { if(regex.IsMatch(t)) { Console.WriteLine(t.Trim()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)