posts - 217, comments - 218, trackbacks - 239

My Links

News




I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net) and born in Bangladesh.
I work for Ocean Informatics Pty Ltd as a Senior Developer - Analyst.
I am also co-founder and core developer of Pageflakes (acquired by LiveUniverse) www.pageflakes.com
and most recently created SmartCodeGenerator

My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

Regex Expression to exclude any code/word from a sentence

Couple of days back I got a query:

What expression will i use in VB validator for the following:
> Allow enter any alpha characters in text box,
> but exclude codes 00 and 50
> Currently my expression looks like  \w{1,20}
> How modify to exclude 00 and 50?

I replied with the following solution:

try this:

[^\s?50|\s?00]\w{1,20}

OR

[^\s?50|\s?00]\w*

both works with the following

Example Text: "Ask me 50 00 times"
Matches:
Ask
me
times

Important Note: But the above expression will eliminate 5 0 characters in any order so it will also eliminate 05 as well.
If you do not want that to happen please try the following expression.
\s?\b((?!\b50\b|\b00\b)\w*)\b\s?
and eliminate any other words which has only 50 or 00 in it.

Here is another variation:
If you want to eliminate any word which has the 50 or 00 anywhere in the sentence use the following.
\b((?!\b\w*50\w*\b|\b\w*00\w*\b)\w*)\b\s?

Example Text: “Ask me 50 times 50times times50 00or50times“

Matches:
Ask
me
times


This Regex is also available at RegexLib.com
http://www.regexlib.com/REDetails.aspx?regexp_id=1244

Print | posted on Saturday, October 29, 2005 10:54 PM |

Feedback

Gravatar

# re: Regex Expression to exclude any code/word from a sentence

i am also stuck with this one but my requirement is little bit different

i have to remove za and zb which is between ka and kb the za zb which are outside of ka kb should not be removed

input is
---------

sample ka za one zb , kb za two zb and za three zb are VERY GOOD

expected result is
--------------------

sample ka one , kb za two zb and za three zb are VERY GOOD
3/12/2008 10:32 PM | pon saravanan

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 5 and type the answer here:

Powered by: