Click here to Skip to main content
13,248,927 members (44,231 online)
Click here to Skip to main content
Add your own
alternative version

Stats

50.4K views
19 bookmarked
Posted 21 Mar 2007

Regular Expressions which are needed in daily coding...

, 21 Mar 2007
Rate this:
Please Sign up or sign in to vote.
Regular Expressions for all purpose..

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..
<tt class="regex"><TAG\b[^>]*>(.*?)</TAG></tt>
//for any HTML tags starting and ending..
<tt class="regex"><([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1></tt>
//For deleting white spaces from text...
<tt class="regex">^[ \t]+|[ \t]+$</tt>
//For Checking IP address between 0..255...
<tt class="regex">\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.</tt><tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9]</tt>
<tt class="regex">[0-9]?)\.</tt><tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.</tt><tt class="regex">
<tt class="regex">(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b</tt><tt class="regex"><tt class="regex"><tt class="regex"> 
//For floating point numbers with sign...
<tt class="regex">[-+]?[0-9]*\.?[0-9]+</tt>
//for floating point numbers with exponents...
<tt class="regex">[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?</tt><tt class="regex"> 
//For email validation...
<tt class="regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">//or you can try for .Museum and etc..</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$</tt></tt></tt></tt></tt></tt>
<tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex"><tt class="regex">
//Date format for yyyy-mm-dd betwwen 1900-01-01 and 2099-12-31
<tt class="regex">(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])</tt>
<tt class="regex">//Date format for mm/dd/yyyy betwwen 1900-01-01 and 2099-12-31 
<tt class="regex">(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d</tt><tt class="regex"> <tt class="regex"> 
//Date format for dd-mm-yyyy betwwen 1900-01-01 and 2099-12-31 
<tt class="regex">(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d</tt> 
//finding word in a string..
<tt class="regex">^.*\b(one|two|three)\b.*$   //one,two,three may be your words...</tt>
//for deleting duplicate lines from text file...
<tt class="regex">^(.*)(\r?\n\1)+$</tt></tt></tt></tt></tt></tt></tt></tt></tt>
//For checking digits..
^[0-9]
//for checking alphabets...
^[a-z]</tt>
<tt class="regex">//REgular Expression for some Credit cards validations...</tt>
<tt class="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}$</tt>
<tt class="regex">
//"enRoute"
^(2014|2149)[0-9]{11}$

//"JCB" 
^3[0-9]{15}$)|(^(2131|1800)[0-9]{11}$)</tt>

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 (GPLv3)

Share

About the Author

JustChiragPatel
Software Developer
India India
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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
NewsThere's a new version of the RegEx Tester Tool ! Pin
BucanerO_Slacker2-Mar-08 0:21
memberBucanerO_Slacker2-Mar-08 0:21 
GeneralFormatting issue Pin
Pete O'Hanlon23-Mar-07 0:32
memberPete O'Hanlon23-Mar-07 0:32 
GeneralDon't be discouraged Pin
Bradml22-Mar-07 23:46
memberBradml22-Mar-07 23:46 
QuestionWhat on earth? Pin
norm .net21-Mar-07 22:57
membernorm .net21-Mar-07 22:57 
AnswerRe: What on earth? Pin
purplepangolin22-Mar-07 5:44
memberpurplepangolin22-Mar-07 5:44 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 5:50
membernorm .net22-Mar-07 5:50 
GeneralRe: What on earth? Pin
purplepangolin22-Mar-07 6:04
memberpurplepangolin22-Mar-07 6:04 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 6:48
membernorm .net22-Mar-07 6:48 
GeneralRe: What on earth? Pin
purplepangolin22-Mar-07 7:17
memberpurplepangolin22-Mar-07 7:17 
GeneralRe: What on earth? Pin
JustChiragPatel22-Mar-07 18:31
memberJustChiragPatel22-Mar-07 18:31 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 22:42
membernorm .net22-Mar-07 22:42 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 22:41
membernorm .net22-Mar-07 22:41 
AnswerRe: What on earth? Pin
ednrgc22-Mar-07 6:20
memberednrgc22-Mar-07 6:20 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 6:49
membernorm .net22-Mar-07 6:49 
AnswerRe: What on earth? Pin
JustChiragPatel22-Mar-07 18:30
memberJustChiragPatel22-Mar-07 18:30 
GeneralRe: What on earth? Pin
norm .net22-Mar-07 22:40
membernorm .net22-Mar-07 22:40 
GeneralRe: What on earth? Pin
John Simmons / outlaw programmer23-Mar-07 1:25
mvpJohn Simmons / outlaw programmer23-Mar-07 1:25 
GeneralRe: What on earth? Pin
norm .net23-Mar-07 2:19
membernorm .net23-Mar-07 2:19 
GeneralRe: What on earth? Pin
John Simmons / outlaw programmer24-Mar-07 0:35
mvpJohn Simmons / outlaw programmer24-Mar-07 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by JustChiragPatel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid