Loading ...

Regex to find the string from the word ending with "ing" and before the fullstop (.)

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Regex to find the string from the word ending with "ing" and before the fullstop (.)

Regex to find the string from the word ending with "ing" and before the fullstop (.)

Posts under the topic: Regex to find the string from the word ending with "ing" and before the fullstop (.)

Posted: 10/19/2010

Lurker 100  points  Lurker
  • Joined on: 9/11/2010
  • Posts: 20

Hi,

I have the following string "This is my text string I know. I am loving it I know." I needto find the string from the word ending with "ing" and before the fullstop (.) so in my sample I need the output as "string I know" and "loving it I know". How can I do it ?


tags regex

Posted: 10/19/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490
  Answered

 

#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. I am loving it I know.";
        string regex = @"([\w]+((?<=\w)ing\b)).+?(?=\.)";
        var matches = Regex.Matches(input, regex);
        foreach (var match in matches)
        {
            Console.WriteLine(match);
        }
        Console.ReadLine();
        //Output
        //string I know
        //loving it I know

    }
}

 


tags regex, c#
Page 1 of 1 (2 items)