posts - 236, comments - 436, trackbacks - 56

My Links

News

Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009


I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes www.pageflakes.com.
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta realestatebazaar.com.bd an ASP.NET MVC application written in C#.NET.


Some of 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

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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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
Gravatar

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

good thanks yuo
http://www.alqaly.com/vb/
9/17/2009 6:24 AM | دردشة
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: