Click here to Skip to main content
6,294,871 members and growing! (16,370 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Beginner License: The GNU General Public License (GPL)

Regular Expressions which are needed in daily coding...

By JustChiragPatel

Regular Expressions for all purpose..
Windows, .NET 1.1, .NET 2.0, ASP.NET, WebForms, VS.NET2003, VS2005, Dev
Posted:21 Mar 2007
Views:17,971
Bookmarked:13 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
20 votes for this article.
Popularity: 2.50 Rating: 1.92 out of 5
13 votes, 65.0%
1
1 vote, 5.0%
2

3

4
6 votes, 30.0%
5

Introduction

Guys , we all know that regular expressions are very useful for checking any kind of patterns.

Background

So we have to know how to write regular expressions for our patterns. But don't worry here i will provide some but very useful regular expressions which will be useful for our coding.

Using the code

just copy and paste Regular Expression from here to your code.
//

// this are the regular expressions for all purposes...

//For checking opening and closing tab of specific HTML tags..

"regex"><TAG\b[^>]*>(.*?)</TAG>
//for any HTML tags starting and ending..

"regex"><([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>
//For deleting white spaces from text...

"regex">^[ \t]+|[ \t]+$
//For Checking IP address between 0..255...

"regex">\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\."regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9]
"regex">[0-9]?)\."regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\."regex">
"regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"regex">"regex">"regex"> 
//For floating point numbers with sign...

"regex">[-+]?[0-9]*\.?[0-9]+
//for floating point numbers with exponents...

"regex">[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"regex"> 
//For email validation...

"regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$
"regex">"regex">"regex">"regex">"regex">"regex">//or you can try for .Museum and etc..

"regex">"regex">"regex">"regex">"regex">"regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$
"regex">"regex">"regex">"regex">"regex">"regex">
//Date format for yyyy-mm-dd betwwen 1900-01-01 and 2099-12-31

"regex">(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])
"regex">//Date format for mm/dd/yyyy betwwen 1900-01-01 and 2099-12-31 

"regex">(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d"regex"> "regex"> 
//Date format for dd-mm-yyyy betwwen 1900-01-01 and 2099-12-31 

"regex">(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d 
//finding word in a string..

"regex">^.*\b(one|two|three)\b.*$   //one,two,three may be your words...

//for deleting duplicate lines from text file...

"regex">^(.*)(\r?\n\1)+$
//For checking digits..

^[0-9]
//for checking alphabets...

^[a-z]
"regex">//REgular Expression for some Credit cards validations...

"regex">
//"Visa"

^[4]([0-9]{15}$|[0-9]{12}$)
//"MasterCard"

^[5][1-5][0-9]{14}$ 

//"Discover" 

^6011-?\\d{4}-?\\d{4}-?\\d{4}$

//"Diners Club" 

(^30[0-5][0-9]{11}$)|(^(36|38)[0-9]{12}$)

//"American Express" 

^[34|37][0-9]{14}$
"regex">
//"enRoute"

^(2014|2149)[0-9]{11}$

//"JCB" 

^3[0-9]{15}$)|(^(2131|1800)[0-9]{11}$)

Points of Interest

I like to Share my knowledge with you, because i am also one of you, taht if i don't know anything then i come to you...so keep excahnge of knowledge...

History

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

JustChiragPatel


Member
Chirag Patel, a Programmer Analyst in a well known IT company working on .NET Technologies since last 2 years. He is interested in Pure business logic and fuzzy logic. his area of interest is in C#.NET, VB.NET and MSSQL 2005.

catch me on: http://groups.google.com/group/codewar
Occupation: Software Developer
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
NewsThere's a new version of the RegEx Tester Tool ! PinmemberBucanerO_Slacker0:21 2 Mar '08  
GeneralFormatting issue PinmemberPete O'Hanlon0:32 23 Mar '07  
GeneralDon't be discouraged PinmemberBradml23:46 22 Mar '07  
GeneralWhat on earth? Pinmembernorm .net22:57 21 Mar '07  
GeneralRe: What on earth? Pinmemberpurplepangolin5:44 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net5:50 22 Mar '07  
GeneralRe: What on earth? Pinmemberpurplepangolin6:04 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net6:48 22 Mar '07  
GeneralRe: What on earth? Pinmemberpurplepangolin7:17 22 Mar '07  
GeneralRe: What on earth? PinmemberJustChiragPatel18:31 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net22:42 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net22:41 22 Mar '07  
GeneralRe: What on earth? Pinmemberednrgc6:20 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net6:49 22 Mar '07  
GeneralRe: What on earth? PinmemberJustChiragPatel18:30 22 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net22:40 22 Mar '07  
GeneralRe: What on earth? PinmvpJohn Simmons / outlaw programmer1:25 23 Mar '07  
GeneralRe: What on earth? Pinmembernorm .net2:19 23 Mar '07  
GeneralRe: What on earth? PinmvpJohn Simmons / outlaw programmer0:35 24 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Mar 2007
Editor:
Copyright 2007 by JustChiragPatel
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project