Posted: 10/19/2010
Hi,
I have the following string "This is my text string I know it. I am loving it I know." I need to find the last word of string after the word ending with "ing" and before the fullstop (.) so in my sample I need the output as "it" and "know". Please help.
#region Using Directives using System; using System.Text.RegularExpressions; #endregion public class Example { static void Main() { string input = "This is my text string I know it. I am loving it I know."; string regex = @"(\w+)(?=(?<=((?<=([\w]+((?<=\w)ing\b)\s)).+?(?=\.)))\.)"; var matches = Regex.Matches(input, regex); foreach (var match in matches) { Console.WriteLine(match); } Console.ReadLine(); //Output: //it //know } }