Monday, September 12, 2011

Regex remove string with a punctuation beside it in a sentence!

Assuming in a sentence, you want to remove the word apply now in any case. This word has a punctuation beside it.
Example:
Apply now!
Apply now.
APPLY NOW!
APPLY NOW.
apply Now!
apply Now.

In a sentence:
We are in need of VB.NET Developers. Apply Now!
We are in need of VB.NET Developers. Apply now!
We are in need of VB.NET Developers. APPLY NOW!
We are in need of VB.NET Developers. apply now!
To remove, just use the code below:
Code:
description = Regex.Replace(description, "apply now[!.]",   string.Empty,RegexOptions.IgnoreCase).Trim();

Note: I'm not a Regex expert.

2 comments:

  1. kuya greg..

    AYA here..

    share lang kog link.. hahha
    http://www.iknowryt.com/2011/09/15/effective-asp-net-training-by-cedf-it/

    ReplyDelete
  2. Cge,

    Sabagay,asp.net man sad ang topic...Related pud sa blog...hehehehe... :-D

    ReplyDelete